forked from 4ducky/4ducky
Move the original PHP site into legacy/
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>
This commit is contained in:
@@ -0,0 +1,258 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
ImageBrowser loads a set of images specified by a search term, user and page.
|
||||
*/
|
||||
|
||||
require_once( 'lib/imagecatalog.php' );
|
||||
|
||||
class ImageBrowser extends ImageCatalog {
|
||||
protected $page = 0;
|
||||
public $thumbsPerPage = 0;
|
||||
protected $commentBool = false;
|
||||
protected $FavBool = false;
|
||||
protected $unreadBool = false;
|
||||
protected $userID = 0;
|
||||
protected $grid = false;
|
||||
public $thumbs = array();
|
||||
public $pages = array();
|
||||
|
||||
|
||||
public function __construct( $thumbsPerPage = 20 ) {
|
||||
$this->thumbsPerPage = abs(intval($thumbsPerPage));
|
||||
}
|
||||
|
||||
public function setPage( $page ) {
|
||||
$page = intval($page);
|
||||
$this->page = $page > 0 ? $page - 1 : 0;
|
||||
}
|
||||
public function setComment( $cmt,$un ) {
|
||||
$this->commentBool = $cmt ;
|
||||
$this->unreadBool = $un;
|
||||
}
|
||||
public function setFav( $fav ) {
|
||||
$this->FavBool = $fav ;
|
||||
}
|
||||
public function setuserID( $id ) {
|
||||
$this->userID = $id ;
|
||||
}
|
||||
|
||||
public function sortByOneKey(array $array, $key, $asc = true) {
|
||||
$result = array();
|
||||
|
||||
$values = array();
|
||||
foreach ($array as $id => $value) {
|
||||
$values[$id] = isset($value[$key]) ? $value[$key] : '';
|
||||
}
|
||||
|
||||
if ($asc) {
|
||||
asort($values);
|
||||
}
|
||||
else {
|
||||
arsort($values);
|
||||
}
|
||||
|
||||
foreach ($values as $key => $value) {
|
||||
$result[$key] = $array[$key];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function multi_unique($myArray)
|
||||
{
|
||||
if(!is_array($myArray))
|
||||
return $myArray;
|
||||
|
||||
foreach ($myArray as &$myvalue){
|
||||
$myvalue=serialize($myvalue);
|
||||
}
|
||||
|
||||
$myArray=array_unique($myArray);
|
||||
|
||||
foreach ($myArray as &$myvalue){
|
||||
$myvalue=unserialize($myvalue);
|
||||
}
|
||||
|
||||
return $myArray;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function load() {
|
||||
$this->grid=true;
|
||||
|
||||
if( !empty( $this->searchColor ) ) { // ----------------------------------- color search
|
||||
$this->thumbs = DB::query(
|
||||
'SELECT SQL_CALC_FOUND_ROWS
|
||||
i.logged, UNIX_TIMESTAMP(i.logged) AS loggedTS,
|
||||
i.keyword, i.thumb, i.score, i.votes,
|
||||
u.name AS userName,
|
||||
MIN( ABS(ic.r - :3) + ABS(ic.g - :4) + ABS(ic.b - :5) ) AS deviation
|
||||
FROM '.TABLE_IMAGES.' i
|
||||
LEFT JOIN '.TABLE_USERS.' u
|
||||
ON u.id = i.user
|
||||
LEFT JOIN '.TABLE_IMAGECOLORS.' ic
|
||||
ON ic.imageId = i.id
|
||||
WHERE
|
||||
ic.r BETWEEN :3 - :6 AND :3 + :6
|
||||
AND
|
||||
ic.g BETWEEN :4 - :6 AND :4 + :6
|
||||
AND
|
||||
ic.b BETWEEN :5 - :6 AND :5 + :6
|
||||
GROUP BY i.id
|
||||
ORDER BY deviation, i.id DESC
|
||||
LIMIT :1, :2',
|
||||
$this->page * $this->thumbsPerPage,
|
||||
$this->thumbsPerPage,
|
||||
|
||||
$this->searchColor['r'],
|
||||
$this->searchColor['g'],
|
||||
$this->searchColor['b'],
|
||||
Config::$colorSearchDev
|
||||
);
|
||||
}
|
||||
else if( $this->searchTerm ) { // ------------------------ fulltext search
|
||||
$ftq = preg_replace( '/\s+/',' +', $this->searchTerm );
|
||||
$this->thumbs = DB::query(
|
||||
'SELECT SQL_CALC_FOUND_ROWS
|
||||
i.logged, UNIX_TIMESTAMP(i.logged) AS loggedTS,
|
||||
i.keyword, i.thumb, i.score, i.votes,
|
||||
u.name AS userName
|
||||
FROM '.TABLE_IMAGES.' i
|
||||
LEFT JOIN '.TABLE_USERS.' u
|
||||
ON u.id = i.user
|
||||
WHERE
|
||||
i.image LIKE :3
|
||||
OR MATCH( i.tags ) AGAINST ( :4 IN BOOLEAN MODE )
|
||||
ORDER BY i.id DESC
|
||||
LIMIT :1, :2',
|
||||
$this->page * $this->thumbsPerPage,
|
||||
$this->thumbsPerPage,
|
||||
|
||||
'%'.$this->searchTerm.'%',
|
||||
$ftq
|
||||
);
|
||||
}
|
||||
|
||||
elseif ($this->commentBool) {
|
||||
|
||||
if($this->unreadBool) {
|
||||
|
||||
$this->thumbs = DB::query("SELECT SQL_CALC_FOUND_ROWS i.logged, UNIX_TIMESTAMP(i.logged) as loggedTS,i.keyword as keyword, i.thumb as thumb, i.score as score, i.votes as votes, us.name as userName FROM pl_images as i, pl_unread as u, pl_users as us WHERE u.userid = :1 AND u.imageid=i.id AND us.id=i.user ORDER BY loggedTS DESC LIMIT :2, :3",$this->userID,
|
||||
$this->page * $this->thumbsPerPage,$this->thumbsPerPage);
|
||||
if (count($this->thumbs) < $this->thumbsPerPage){
|
||||
$this->thumbsPerPage = count($this->thumbs);}
|
||||
|
||||
}else{
|
||||
$this->thumbs = DB::query('SELECT SQL_CALC_FOUND_ROWS i.logged, UNIX_TIMESTAMP(i.logged) as loggedTS,i.keyword as keyword, i.thumb as thumb, i.score as score, i.votes as votes, u.name as userName FROM pl_comments as c, pl_images as i, pl_users as u WHERE c.c_like=0 AND c.userId=u.id AND c.userId=:1 AND i.id=c.imageId GROUP BY c.imageId ORDER BY loggedTS DESC LIMIT :2, :3',$this->userID,
|
||||
$this->page * $this->thumbsPerPage,$this->thumbsPerPage);
|
||||
|
||||
}
|
||||
|
||||
|
||||
$this->commentState = true;
|
||||
$this->basePath = "comments/";
|
||||
|
||||
|
||||
|
||||
|
||||
}elseif ($this->FavBool) {
|
||||
$this->thumbs = DB::query("SELECT SQL_CALC_FOUND_ROWS i.logged, UNIX_TIMESTAMP( i.logged ) AS loggedTS, i.keyword AS keyword, i.thumb AS thumb, i.score AS score, i.votes AS votes, u.name AS userName
|
||||
FROM pl_fav AS c, pl_images AS i, pl_users AS u
|
||||
WHERE c.user = u.id
|
||||
AND c.user =:1
|
||||
AND i.id = c.imageId
|
||||
GROUP BY c.imageId
|
||||
ORDER BY loggedTS DESC LIMIT :2, :3",$this->userID,
|
||||
$this->page * $this->thumbsPerPage,$this->thumbsPerPage);
|
||||
$this->basePath = "favorites/";
|
||||
$this->FavState = true;
|
||||
|
||||
|
||||
}else { // -------------------------------------------------------- user/all
|
||||
$conditions = '';
|
||||
if( !empty($this->user) ) {
|
||||
$conditions .= ' AND i.user = :3';
|
||||
}
|
||||
|
||||
$this->thumbs = DB::query(
|
||||
'SELECT SQL_CALC_FOUND_ROWS
|
||||
i.logged, UNIX_TIMESTAMP(i.logged) AS loggedTS,
|
||||
i.keyword, i.thumb, i.score, i.votes,
|
||||
u.name AS userName
|
||||
FROM '.TABLE_IMAGES.' i
|
||||
LEFT JOIN '.TABLE_USERS.' u
|
||||
ON u.id = i.user
|
||||
WHERE 1 '.$conditions.'
|
||||
ORDER BY i.id DESC
|
||||
LIMIT :1, :2',
|
||||
|
||||
|
||||
|
||||
$this->page * $this->thumbsPerPage,
|
||||
$this->thumbsPerPage,
|
||||
$this->user['id']
|
||||
);
|
||||
|
||||
$this->grid=true;
|
||||
if(count($this->thumbs) > 3){
|
||||
$this->thumbs[0]["score"] = "100";
|
||||
$this->thumbs[1]["score"] = "10";
|
||||
$this->thumbs[2]["score"] = "10";
|
||||
|
||||
$thumbsCount = count($this->thumbs);
|
||||
if ($thumbsCount > 50){
|
||||
for ($i=$thumbsCount-40; $i<$thumbsCount; $i++){
|
||||
$this->thumbs[$i]["score"] = "0";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->totalResults = DB::foundRows();
|
||||
|
||||
|
||||
// compute previoues, current and next page
|
||||
if( $this->totalResults > 0 ) {
|
||||
$this->pages['current'] = $this->page+1;
|
||||
$this->pages['total'] = ceil($this->totalResults / $this->thumbsPerPage);
|
||||
if( $this->page > 0 ) {
|
||||
$this->pages['prev'] = $this->page;
|
||||
}
|
||||
if( $this->totalResults > $this->thumbsPerPage * $this->page + $this->thumbsPerPage ) {
|
||||
$this->pages['next'] = $this->page + 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function loadRandom( $minScore, $thumbSize ) {
|
||||
$this->thumbs = DB::query(
|
||||
'SELECT SQL_CALC_FOUND_ROWS
|
||||
i.logged, UNIX_TIMESTAMP(i.logged) AS loggedTS,
|
||||
i.keyword, i.thumb, i.score, i.votes,
|
||||
u.name AS userName
|
||||
FROM '.TABLE_IMAGES.' i
|
||||
LEFT JOIN '.TABLE_USERS.' u
|
||||
ON u.id = i.user
|
||||
WHERE i.score >= :2
|
||||
ORDER BY RAND()
|
||||
LIMIT :1',
|
||||
|
||||
$this->thumbsPerPage,
|
||||
$minScore
|
||||
);
|
||||
|
||||
foreach( array_keys( $this->thumbs ) as $i ) {
|
||||
$this->thumbs[$i]['thumb'] = Config::$images['thumbPath'] .
|
||||
str_replace( '-', '/', substr( $this->thumbs[$i]['logged'], 0, 7 ) )
|
||||
.'/'. $thumbSize
|
||||
.'/'. $this->thumbs[$i]['thumb'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user