'
@@ -2419,24 +2425,18 @@ static function getLastComment($board, $thread_id) {
* @return Array
* @param int $thread_id int
*/
- static function getLastUnreadComment($board, $thread_id, $user_id) {
+ static function getLastUnreadComment($board, $thread_id, $user_id)
+ {
global $db;
- $sql =
- "
- SELECT
- comments.*
- , UNIX_TIMESTAMP(comments.date) as date
- FROM comments
- LEFT JOIN comments_unread
- ON (comments.id = comments_unread.comment_id AND comments_unread.user_id = ".$user_id.")
- WHERE
- comments_unread.comment_id is NOT NULL
- AND comments.thread_id = ".$thread_id."
- AND comments.board='".$board."'
- ORDER by date ASC LIMIT 0,1
- "
- ;
- return $db->fetch($db->query($sql, __FILE__, __LINE__));
+ $sql = 'SELECT comments.*, UNIX_TIMESTAMP(comments.date) as date
+ FROM comments LEFT JOIN comments_unread
+ ON (comments.id = comments_unread.comment_id AND comments_unread.user_id=?)
+ WHERE
+ comments_unread.comment_id is NOT NULL
+ AND comments.thread_id=?
+ AND comments.board=?
+ ORDER by date ASC LIMIT 1';
+ return $db->fetch($db->query($sql, __FILE__, __LINE__, __METHOD__, [$user_id, $thread_id, $board]));
}
/**
@@ -2504,8 +2504,8 @@ static function getNumPosts($board, $thread_id)
if (empty($board) || is_numeric($board) || is_bool($board)) return false;
if (empty($thread_id) || !is_numeric($thread_id) || $thread_id <= 0) return false;
- $sql = 'SELECT id FROM comments WHERE thread_id = '.$thread_id.' AND board="'.$board.'"';
- return $db->num($db->query($sql, __FILE__, __LINE__, __METHOD__));
+ $sql = 'SELECT id FROM comments WHERE thread_id=? AND board=?';
+ return $db->num($db->query($sql, __FILE__, __LINE__, __METHOD__, [$thread_id, $board]));
}
/**
@@ -2546,9 +2546,8 @@ static function getNumUnread ($board, $thread_id, $user_id=null) {
$sql = 'SELECT count(c.id) anz
FROM comments c, comments_unread u
- WHERE c.board = "'.$board.'" AND c.thread_id='.$thread_id.' AND u.comment_id=c.id AND u.user_id='.$user_id
- ;
- $d = $db->fetch($db->query($sql, __FILE__, __LINE__, __METHOD__));
+ WHERE c.board=? AND c.thread_id=? AND u.comment_id=c.id AND u.user_id=?';
+ $d = $db->fetch($db->query($sql, __FILE__, __LINE__, __METHOD__, [$board, $thread_id, $user_id]));
return $d['anz'];
}
@@ -2571,9 +2570,8 @@ static function getRecordset($board, $thread_id) {
if (empty($board) || is_numeric($board) || is_array($board)) return false;
if (empty($thread_id) || !is_numeric($thread_id) || $thread_id <= 0 || is_array($thread_id)) return false;
- $sql = 'SELECT *, UNIX_TIMESTAMP(date) as date
- FROM comments where thread_id='.$thread_id.' and board="'.$board.'"';
- return $db->fetch($db->query($sql, __FILE__, __LINE__, __METHOD__));
+ $sql = 'SELECT *, UNIX_TIMESTAMP(date) as date FROM comments where thread_id=? and board=?';
+ return $db->fetch($db->query($sql, __FILE__, __LINE__, __METHOD__, [$thread_id, $board]));
}
/**
@@ -2595,23 +2593,22 @@ static function printChildPosts($board, $parent_id, $depth=array("space")) {
}
$hierdepth = count($depth);
- $sql =
- "SELECT"
- ." comments.*"
- .", user.clan_tag, user.username"
- .", comments_unread.user_id as isunread"
- .", UNIX_TIMESTAMP(comments.date) as date"
- .", count(c2.id) as numchildposts"
- ." FROM comments"
- ." LEFT JOIN comments_unread ON (comments.id=comments_unread.comment_id AND comments_unread.user_id = '".$_SESSION['user_id']."')"
- ." LEFT JOIN user ON comments.user_id = user.id"
- ." LEFT JOIN comments as c2 ON (comments.id = c2.parent_id AND comments.board = c2.board)"
- ." WHERE comments.parent_id = $parent_id AND comments.board = '".$board."'"
- ." GROUP BY comments.id"
- ." ORDER BY comments.id"
- ;
+ $sql = 'SELECT
+ comments.*
+ ,user.clan_tag, user.username
+ ,comments_unread.user_id as isunread
+ ,UNIX_TIMESTAMP(comments.date) as date
+ ,count(c2.id) as numchildposts
+ FROM comments
+ LEFT JOIN comments_unread ON (comments.id=comments_unread.comment_id AND comments_unread.user_id=?)
+ LEFT JOIN user ON comments.user_id=user.id
+ LEFT JOIN comments as c2 ON (comments.id=c2.parent_id AND comments.board=c2.board)
+ WHERE comments.parent_id=? AND comments.board=?
+ GROUP BY comments.id
+ ORDER BY comments.id
+ ';
- $result = $db->query($sql, __FILE__, __LINE__, __METHOD__);
+ $result = $db->query($sql, __FILE__, __LINE__, __METHOD__, [$user->id, $parent_id, $board]);
$rcount = 0;
$additional = FALSE; // already posted "Additional Posts" ?
while($rs = $db->fetch($result)) {
diff --git a/www/includes/gallery.inc.php b/www/includes/gallery.inc.php
index 557c4a4..595f33d 100644
--- a/www/includes/gallery.inc.php
+++ b/www/includes/gallery.inc.php
@@ -3,49 +3,44 @@
* Gallery Funktionen
*
* Beinhaltet alle Funktionen der Gallery.
+ * @TODO Move LAYOUT FUNCTIONS to Template Engine
+ * @TODO Wasserzeichen(?)
*
- * @author [z]biko
- * @package zorg\Gallery
- * @version 3.0
- * @since 1.0 File & functions added
+ * @version 3.5
+ * @since 1.0 `[z]biko` File added
* @since 2.0 Added code documentations, polished & optimized various functions
* @since 3.0 `09.08.2018` `IneX` Refactored picPath() & createPic(), added APOD specific specials
+ * @since 3.5 `24.12.2023` `IneX` Code optimizations and refactorings
*
- * @TODO MyPic-Markierung von Bildern
- * @TODO Wasserzeichen(?)
+ * @package zorg\Gallery
*/
+
+/**
+ * Configs
+ *
+ * set_time_limit Maximale Zeit in Sekunden, welche das Script laufen darf
+ */
+set_time_limit(600);
+
/**
* File includes
* @include config.inc.php
* @include forum.inc.php
- * @include util.inc.php
+ * @include util.inc.php DISABLED is part of config.inc.php
* @include usersystem.inc.php
*/
require_once dirname(__FILE__).'/config.inc.php';
include_once INCLUDES_DIR.'forum.inc.php';
-require_once INCLUDES_DIR.'util.inc.php';
+//require_once INCLUDES_DIR.'util.inc.php';
require_once INCLUDES_DIR.'usersystem.inc.php';
-/**
- * @const set_time_limit Maximale Zeit in Sekunden, welche das Script laufen darf
- * @const FTP_UPDIT FTP-Serveraddress and Directory-Path to Gallery Upload Dir
- * @const DIR Path to Gallery directory on the server
- * @const UPDIR Path to the Upload directory on the server
- * @const ZENSUR If the User is a Member, he can see censored Pics. Otherwise the SQL-Query addition will filter them out.
- */
-set_time_limit(600);
-define('FTP_UPDIR', 'ftp://zooomclan@zorg.ch/data/gallery/upload/incoming/'); // @DEPRECATED
-define('DIR', $_SERVER['DOCUMENT_ROOT'].'/../data/gallery/'); // @DEPRECATED Replaced with GALLERY_DIR in config.inc.php
-define('UPDIR', $_SERVER['DOCUMENT_ROOT'].'/../data/upload/'); // @DEPRECATED Replaced with GALLERY_UPLOAD_DIR in config.inc.php
-define('ZENSUR', ( $user->typ >= USER_MEMBER ? '' : 'AND p.zensur="0"' ));
-
/**
* Globals
- * @var array $MAX_PIC_SIZE The maximum width & height for pictures
- * @var array $THUMBPAGE The image size for Thumbnail pictures
+ * @const ZENSUR SQL-Query addition if the User is a Member (it can see censored Pics), otherwise filter them out.
+ * @const THUMBPAGE The number of Thumbnail pictures per column and page (rows) when rendering the layout
*/
-$MAX_PIC_SIZE = array('picWidth'=>800, 'picHeight'=>800, 'tnWidth'=>150, 'tnHeight'=>150);
-$THUMBPAGE = array('width'=>4, 'height'=>3, 'padding'=>10);
+define('ZENSUR', ($user->typ >= USER_MEMBER ? '' : 'AND p.zensur="0"'));
+define('THUMBPAGE', ['cols'=>4, 'rows'=>3, 'padding'=>10]);
// ********************************** LAYOUT FUNCTIONS ***************************************************************************
@@ -54,23 +49,21 @@
*
* Zeigt die Gallery-Ãœbersicht mit allen Alben
*
- * @author [z]biko
- * @version 1.0
- * @since 1.0 function added
+ * @version 1.5
+ * @since 1.0 `[z]biko` function added
+ * @since 1.5 `24.12.2023` `IneX` Optimizations and refactorings
*
+ * @uses USER_MEMBER, ZENSUR
* @param string $state Aktueller Status des Albums, z.B. wenn es gerade bearbeitet wird
* @param string $error (Fehler-)Meldung, welche auf der Gallery-Seite angezeigt werden soll
* @global object $db Globales Class-Object mit allen MySQL-Methoden
* @global object $user Globales Class-Object mit den User-Methoden & Variablen
* @global object $smarty Globales Class-Object mit allen Smarty-Methoden
- * @global array $MAX_PIC_SIZE Variable mit den Werten aus $MAX_PIC_SIZE
- * @global array $THUMBPAGE Variable mit den Werten aus $THUMBPAGE
- * @uses USER_MEMBER, ZENSUR
* @return string HTML-Code der Gallery-Seite
*/
function galleryOverview ($state="", $error="")
{
- global $db, $user, $MAX_PIC_SIZE, $THUMBPAGE, $smarty;
+ global $db, $user, $smarty;
/** Error Output (function backwards compatibility) */
if ((isset($state) || isset($error)) && $user->typ >= USER_MEMBER)
@@ -145,40 +138,38 @@ function galleryOverview ($state="", $error="")
/**
* Album Thumbnails anzeigen
*
- * @version 2.0
+ * @version 2.1
* @since 1.0 function added
* @since 1.5 moved pagination to new Sidebar, output it via $smarty
* @since 2.0 `16.12.2022` `IneX` lazy-loaded responsive Gallery Album Thumbs Overview
+ * @since 2.1 `24.12.2023` `IneX` Optimizations and refactorings
*
* @param integer $id ID des Albums von welchem die Thumbnails angezeigt werden sollen
* @param integer $page Aktuelle Seite des Albums, deren Thumbnails angezeigt werden sollen
* @global object $db Globales Class-Object mit allen MySQL-Methoden
* @global object $user Globales Class-Object mit den User-Methoden & Variablen
* @global object $smarty Globales Class-Object mit allen Smarty-Methoden
- * @global array $MAX_PIC_SIZE Variable mit den Werten aus $MAX_PIC_SIZE
- * @global array $THUMBPAGE Variable mit den Werten aus $THUMBPAGE
- * @uses ZENSUR
+ * @uses THUMBPAGE, ZENSUR
* @uses user_error(), self::imgsrcThum(), Thread::getNumPosts(), Thread::getNumUnread()
*/
-function albumThumbs ($id, $page=0) {
- global $db, $THUMBPAGE, $MAX_PIC_SIZE, $user, $smarty;
+function albumThumbs ($id, $page=0)
+{
+ global $db, $user, $smarty;
- if (!is_numeric($id) || $id <= 0)
- {
- user_error('Missing Parameter id', E_USER_ERROR);
- exit;
- }
+ if (!is_numeric($id) || $id <= 0) user_error('Missing Parameter id', E_USER_ERROR);
+ if (!is_numeric($page) || $page < 0) user_error('Missing Parameter page', E_USER_ERROR);
- $pagepics = $THUMBPAGE['width'] * $THUMBPAGE['height'];
+ $pagepics = THUMBPAGE['cols'] * THUMBPAGE['rows'];
$e = $db->query('SELECT count(id) anz FROM gallery_pics p WHERE album='.$id.' '.ZENSUR.' GROUP BY album', __FILE__, __LINE__, __FUNCTION__);
- $d = mysqli_fetch_array($e);
+ $d = $db->fetch($e);
$anz = $d['anz'];
$htmlOutput = null;
$sidebarHtml = null;
if (!empty($d) && $d['anz'] > 0)
{
- $e = $db->query(sprintf('SELECT g.id, g.name, IF(e.enddate != "0000-00-00 00:00:00" AND g.created IS NULL, e.enddate, g.created) created, e.id eventid, e.name eventname, GROUP_CONCAT(eu.user_id SEPARATOR ",") beenthere_users
+ $e = $db->query(sprintf('SELECT
+ g.id, g.name, IF(e.enddate != "0000-00-00 00:00:00" AND g.created IS NULL, e.enddate, g.created) created, e.id eventid, e.name eventname, GROUP_CONCAT(eu.user_id SEPARATOR ",") beenthere_users
FROM gallery_albums g LEFT JOIN events e ON e.gallery_id=g.id LEFT JOIN events_to_user eu ON eu.event_id=e.id
WHERE g.id=%d GROUP BY g.id, e.enddate, e.id, e.name', $id), __FILE__, __LINE__, __FUNCTION__);
$d = $db->fetch($e);
@@ -186,8 +177,8 @@ function albumThumbs ($id, $page=0) {
if ($user->typ == USER_MEMBER) $htmlOutput .= ' [edit name] [add pics] ';
$e = $db->query('SELECT * FROM gallery_pics p WHERE album='.$id.' '.ZENSUR.' ORDER BY p.id LIMIT '.($page*$pagepics).', '.$pagepics, __FILE__, __LINE__, __FUNCTION__);
- $hgt = $MAX_PIC_SIZE['tnHeight'] + 2 * $THUMBPAGE['padding'];
- $wdt = $MAX_PIC_SIZE['tnWidth'] + 2 * $THUMBPAGE['padding'];
+ // $hgt = MAX_THUMBNAIL_SIZE['height'] + 2 * THUMBPAGE['padding'];
+ // $wdt = MAX_THUMBNAIL_SIZE['width'] + 2 * THUMBPAGE['padding'];
$rows = 1;
$htmlOutput .= '';
while ($pic = $db->fetch($e))
@@ -247,37 +238,33 @@ function albumThumbs ($id, $page=0) {
/**
* Bild anzeigen
*
- * @author [z]biko
- * @author IneX
- * @version 2.4
+ * @version 2.5
* @since 1.0 `21.10.2013` `[z]biko` function added
* @since 2.0 `01.10.2019` `IneX` APOD Special: statt Pic ein Video embedden
* @since 2.1 `01.10.2019` `IneX` responsive scaling `img` and |