Skip to content

Commit

Permalink
zorg Code v4.5.1-hotfix2
Browse files Browse the repository at this point in the history
Merge pull request #68 from zorgch/develop
  • Loading branch information
oliveratgithub authored Dec 27, 2022
2 parents 0d7b68b + 8c01a2e commit f10957c
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 79 deletions.
2 changes: 1 addition & 1 deletion www/css/css.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
font-size: 0.4rem;
}
header > .infos .solarstate .event { margin-right: 5px; }
header > .onlineuser { font-size: 0.4rem; }
header > .onlineuser { font-size: 0.4rem; text-align: right; }
header > .notifications { font-size: 0.4rem; }
.navigation { font-size: 0.5rem; }
div.menu { overflow-x: auto; }
Expand Down
44 changes: 22 additions & 22 deletions www/forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,6 @@

$model->showThread($smarty, $thread['thread_id'], $thread['text']);

/** Comment is the Thread-Comment */
if ($parent_id === 1)
{
$comments_resource = ($showCommentId === $thread['thread_id'] ? $thread['board'].'-'.$showCommentId : $showCommentId);
if (DEVELOPMENT === true) error_log(sprintf('[DEBUG] <%s:%d> $parent_id == %d: %s', __FILE__, __LINE__, $parent_id, $comments_resource));
$outputContent .= $smarty->fetch('comments:'.$comments_resource);
}
/** Comment is a regular (Sub-)Comment */
else {
if (DEVELOPMENT === true) error_log(sprintf('[DEBUG] <%s:%d> $parent_id == %d: id=%d', __FILE__, __LINE__, $parent_id, $showCommentId));
$smarty->assign('comments_top_additional', 1);
$outputContent .= $smarty->fetch('comments:'.$showCommentId);
}

/** Zusätzliche Features & Output nur bei eingeloggten Usern... */
if ($user->is_loggedin())
{
Expand All @@ -142,15 +128,29 @@
);
while ($d = $db->fetch($e)) $comments_unread[] = $d['comment_id'];
$smarty->assign('comments_unread', $comments_unread);
}

/** Commentform zum posten printen */
if ($no_form === false)
{
$smarty->assign('board', 'f');
$smarty->assign('thread_id', Comment::getThreadid('f', $showCommentId));
$smarty->assign('parent_id', $showCommentId);
$outputContent .= $smarty->fetch('file:layout/partials/commentform.tpl');
}
/** Comment is the Thread-Comment */
if ($parent_id === 1)
{
$comments_resource = ($showCommentId === $thread['thread_id'] ? $thread['board'].'-'.$showCommentId : $showCommentId);
if (DEVELOPMENT === true) error_log(sprintf('[DEBUG] <%s:%d> $parent_id == %d: %s', __FILE__, __LINE__, $parent_id, $comments_resource));
$outputContent .= $smarty->fetch('comments:'.$comments_resource);
}
/** Comment is a regular (Sub-)Comment */
else {
if (DEVELOPMENT === true) error_log(sprintf('[DEBUG] <%s:%d> $parent_id == %d: id=%d', __FILE__, __LINE__, $parent_id, $showCommentId));
$smarty->assign('comments_top_additional', 1);
$outputContent .= $smarty->fetch('comments:'.$showCommentId);
}

/** Commentform zum posten printen (bei eingeloggten Usern) */
if ($user->is_loggedin() && $no_form === false)
{
$smarty->assign('board', 'f');
$smarty->assign('thread_id', Comment::getThreadid('f', $showCommentId));
$smarty->assign('parent_id', $showCommentId);
$outputContent .= $smarty->fetch('file:layout/partials/commentform.tpl');
}
}

Expand Down
9 changes: 4 additions & 5 deletions www/gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
$doAction = (string)$_GET['do'];
/** Das Benoten (und mypic markieren) können nebst Schönen auch die registrierten User,
deshalb müssen wirs vorziehen... */
if ($user->is_loggedin() && isset($_POST['picID']) && !empty($_POST['picID']) && $_POST['picID'] > 0)
if ($user->is_loggedin() && ($doAction === 'benoten' || $doAction === 'mypic') && isset($_POST['picID']) && !empty($_POST['picID']) && $_POST['picID'] > 0)
{
switch ($doAction)
{
Expand All @@ -83,12 +83,12 @@
}
break;
}
} else {
} elseif (!$user->is_loggedin() && !empty($doAction)) {
$smarty->assign('error', ['type' => 'warn', 'dismissable' => 'false', 'title' => t('permissions-insufficient', 'gallery', [$doAction])]);
}

/** Ab hier kommt nur noch Zeugs dass Member & Schöne machen dürfen */
if ($user->typ >= USER_MEMBER)
if ($user->typ >= USER_MEMBER && (!empty($doAction) && $doAction != 'benoten' && $doAction != 'mypic'))
{
switch ($doAction)
{
Expand Down Expand Up @@ -128,9 +128,8 @@
/*case 'markieren':
doMark($getPicId);
break;*/

}
} else {
} elseif ($user->typ < USER_MEMBER && !empty($doAction)) {
$smarty->assign('error', ['type' => 'warn', 'dismissable' => 'false', 'title' => t('permissions-insufficient', 'gallery', [$doAction])]);
}

Expand Down
70 changes: 37 additions & 33 deletions www/includes/comments.res.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,38 +242,36 @@ function smartyresource_comments_get_commenttree ($id, $is_thread=false) {
'{/foreach}';

$html .=
'<td align="left" class="border forum">'
.'{if $user->id!=0 && in_array('.$rs['id'].', $comments_unread)}'
.'{assign var=comment_color value=$color.newcomment}'
.'{comment_mark_read comment_id="'.$rs['id'].'" user_id=$user->id}'
.'{elseif $user->id == '.$rs['user_id'].'}'
.'{assign var=comment_color value=$color.owncomment}'
.'{else}'
.'{assign var=comment_color value=$color.background}'
.'{/if}'
.'{capture assign="sizeof_hdepth"}{sizeof array=$hdepth}{/capture}'
.'<table bgcolor="{comment_colorfade depth=$sizeof_hdepth color=$comment_color}" style="table-layout:fixed;" width="100%">'
.'<tr class="tiny">'
.'<td class="forum comment meta left" style="width: {if $user->from_mobile}85%{else}70%{/if};">'
.'<div style="display: none;" itemscope itemtype="http://schema.org/Organization" itemprop="publisher"><span style="display: none;" itemprop="name">{$smarty.const.SITE_HOSTNAME}</span></div>'
.'<a href="{comment_get_link board='.$rs['board'].' parent_id='.$rs['parent_id'].' id='.$rs['id'].' thread_id='.$rs['thread_id'].'}" name="'.$rs['id'].'"'.($is_thread ? ' itemprop="url"' : '').'>'
.'#'.$rs['id']
.'</a>'
.' by <span itemprop="'.($is_thread ? 'author' : 'contributor').'" itemscope itemtype="http://schema.org/Person">'.$user->userpagelink($rs['user_id'], $rs['clan_tag'], $rs['username'])
.'</span> @ <meta itemprop="datePublished" content="{'.$rs['date'].'|date_format:"%Y-%m-%d"}">{datename date='.$rs['date'].'}'
'<td align="left" class="border forum">'
.'{if $user->id>0 && in_array('.$rs['id'].', $comments_unread)}'
.'{assign var=comment_color value=$color.newcomment}'
.'{comment_mark_read comment_id="'.$rs['id'].'" user_id=$user->id}'
.'{elseif $user->id == '.$rs['user_id'].'}'
.'{assign var=comment_color value=$color.owncomment}'
.'{else}'
.'{assign var=comment_color value=$color.background}'
.'{/if}'
.'{capture assign="sizeof_hdepth"}{sizeof array=$hdepth}{/capture}'
.'<table bgcolor="{comment_colorfade depth=$sizeof_hdepth color=$comment_color}" style="table-layout:fixed;" width="100%">'
.'<tr class="tiny">'
.'<td class="forum comment meta left" style="width: {if $user->from_mobile}85%{else}70%{/if};">'
.'<div style="display: none;" itemscope itemtype="http://schema.org/Organization" itemprop="publisher"><span style="display: none;" itemprop="name">{$smarty.const.SITE_HOSTNAME}</span></div>'
.'<a href="{comment_get_link board='.$rs['board'].' parent_id='.$rs['parent_id'].' id='.$rs['id'].' thread_id='.$rs['thread_id'].'}" name="'.$rs['id'].'"'.($is_thread ? ' itemprop="url"' : '').'>'
.'#'.$rs['id']
.'</a>'
.' by <span itemprop="'.($is_thread ? 'author' : 'contributor').'" itemscope itemtype="http://schema.org/Person">'.$user->userpagelink($rs['user_id'], $rs['clan_tag'], $rs['username'])
.'</span> @ <meta itemprop="datePublished" content="{'.$rs['date'].'|date_format:"%Y-%m-%d"}">{datename date='.$rs['date'].'}'
;

if($rs['date_edited'] > 0) {
$html .= ', edited @ <meta itemprop="dateModified" content="{'.$rs['date_edited'].'|date_format:"%Y-%m-%d-T%H:00"}">{datename date='.$rs['date_edited'].'}';
}

$html .= '<!--googleoff: all-->';
$html .=
' <a href="#top" class="dont-wrap">- {if $user->from_mobile}top{else}nach oben{/if} -</a> '
.'</td><td class="forum comment meta dont-wrap align-right hide-mobile" style="width: 15%;">'
;
$html .= '<a href="#top" class="dont-wrap">{if $user->from_mobile} - top -{else} - nach oben -{/if}</a>';
$html .= '</td><td class="forum comment meta dont-wrap align-right hide-mobile" style="width: 15%;">';

// Subscribe / Unsubscribe
/** Subscribe / Unsubscribe */
$html .= '{if $user->id > 0}'
.'{if in_array('.$rs['id'].', $comments_subscribed)}
<a href="/actions/commenting.php'
Expand All @@ -287,18 +285,24 @@ function smartyresource_comments_get_commenttree ($id, $is_thread=false) {
{/if}
{/if}';

/** Edit Comment */
$html .= '{if $user->id == '.$rs['user_id'].'}'
.'<a href="/forum.php?layout=edit&parent_id='.$rs['parent_id'].'&id='.$rs['id'].'&url={$request.url|base64encodeurl}">[edit]</a> '
.'{/if}
{if $user->id != 0}'
.'</td><td class="forum comment meta right align-right" style="width: 15%;">'
.'<label for="replyfor-'.$rs['id'].'" class="dont-wrap" style="margin-right: 2px;">'
.'<input type="radio" class="replybutton" name="parent_id" id="replyfor-'.$rs['id'].'" onClick="reply()" value="'.$rs['id'].'" '
.'{if $smarty.get.parent_id == '.$rs['id'].'} checked="checked" {/if} /><span class="hide-mobile">&nbsp;reply</span></label>'
.'{/if}';
.'<a href="/forum.php?layout=edit&parent_id='.$rs['parent_id'].'&id='.$rs['id'].'&url={$request.url|base64encodeurl}">[edit]</a> '
.'{/if}';

/** Reply-to Comment */
$html .= '{if $user->id > 0}'
.'</td><td class="forum comment meta right align-right" style="width: 15%;">'
.'<label for="replyfor-'.$rs['id'].'" class="dont-wrap" style="margin-right: 2px;">'
.'<input type="radio" class="replybutton" name="parent_id" id="replyfor-'.$rs['id'].'" onClick="reply()" value="'.$rs['id'].'"'
.'{if $smarty.get.parent_id == '.$rs['id'].'} checked="checked"{/if}'
.'/><span class="hide-mobile">&nbsp;reply</span>'
.'</label>'
.'{/if}';
$html .= '<!--googleon: all-->';
$html .= '</td></tr><tr>';
$html .= '</td></tr>';

$html .= '<tr>';
($is_thread ? $html .= '<span itemprop="headline" content="'.remove_html(Comment::getLinkThread($rs['board'], $rs['thread_id'])).'"></span>' : '');
$html .= '<td class="forum comment" colspan="3" itemprop="'.($is_thread ? 'articleBody' : 'text').'">';
if (!$rs['error']) {
Expand Down
6 changes: 3 additions & 3 deletions www/includes/gallery.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ function pic ($id)
/** Bild Zensur-Info */
if ($cur['zensur'] === '1') echo '<span class="small" title="Bild ist ZENSIERT">🫥</span>';
/** Bild Datum (Desktop Viewports) */
if (!$user->from_mobile && is_file($pic_filepath) !== false)
if ((!isset($user->from_mobile) || false === $user->from_mobile) && is_file($pic_filepath) !== false)
{
/** APOD Special: use pic_added from database, instead of filemtime */
if ($cur['album'] == APOD_GALLERY_ID && !empty($cur['timestamp'])) {
Expand Down Expand Up @@ -434,7 +434,7 @@ function pic ($id)
echo '</td></tr>';

/** Bild Datum (Mobile Viewports) */
if ($user->from_mobile != false && is_file($pic_filepath) !== false)
if (isset($user->from_mobile) && $user->from_mobile != false && is_file($pic_filepath) !== false)
{
echo '<tr><td colspan="3" class="align-right padding-bottom-s small light">';
/** APOD Special: use pic_added from database, instead of filemtime */
Expand Down Expand Up @@ -507,7 +507,7 @@ function pic ($id)
/**
* Mobile Touch Swipe - next/prev Pic
*/
if ($user->from_mobile != false)
if (isset($user->from_mobile) && $user->from_mobile != false)
{
echo '<script>// HammerJS
document.onreadystatechange = function(){
Expand Down
21 changes: 15 additions & 6 deletions www/js/ajax/get-onlineuser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@
*
* @package zorg\Usersystem
*/

/**
* AJAX Request validation
*/
if (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
/** The request is not an AJAX request */
http_response_code(405); // Set response code 405 (Method Not Allowed)
exit('Request not allowed');
}
if(!isset($_GET['style']) || empty($_GET['style']) || false === filter_var(trim($_GET['style']), FILTER_SANITIZE_STRING))
{
http_response_code(400); // Set response code 400 (bad request) and exit.
die('Invalid or missing GET-Parameter');
exit('Invalid or missing GET-Parameter');
} else {
$onlineUserListstyle = filter_var(trim($_GET['style']), FILTER_SANITIZE_STRING);
}
$onlineUserListstyle = filter_var(trim($_GET['style']), FILTER_SANITIZE_STRING);

/**
* Get online user HTML
Expand All @@ -21,16 +28,17 @@
{
case 'image':
/** Requires usersystem.inc.php */
require_once INCLUDES_DIR.'usersystem.inc.php';
require_once __DIR__.'/../../includes/usersystem.inc.php';
$onlineUserHtml = $user->online_users(true);

if (!empty($onlineUserHtml))
{
http_response_code(200); // Set response code 200 (OK)
header('Content-type: text/html; charset=utf-8');
echo $onlineUserHtml;
exit($onlineUserHtml);
} else {
http_response_code(204); // Set response code 204 (OK but no Content)
exit;
}
break;

Expand All @@ -55,15 +63,16 @@
}
http_response_code(200); // Set response code 200 (OK)
header('Content-type: text/html; charset=utf-8');
echo implode(', ', $onlineUsersArr);
exit(implode(', ', $onlineUsersArr));
}
/** No logged-in user seems to be online... */
else {
http_response_code(204); // Set response code 204 (OK but no Content)
exit;
}
break;

default:
http_response_code(400); // Set response code 400 (Bad Request)
die('Invalid GET-Parameter');
exit('Invalid GET-Parameter');
}
17 changes: 12 additions & 5 deletions www/js/ajax/get-unreadcomments.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@
*
* @package zorg\Forum
*/

/**
* AJAX Request validation
*/
if (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
/** The request is not an AJAX request */
http_response_code(405); // Set response code 405 (Method Not Allowed)
exit('Request not allowed');
}
if(!isset($_GET['user']) || empty($_GET['user']) || false === filter_var(trim($_GET['user']), FILTER_SANITIZE_NUMBER_INT))
{
http_response_code(400); // Set response code 400 (bad request) and exit.
Expand All @@ -22,24 +28,25 @@
* The reason is to have a very minimal "overhead" for repeated
* checks for unread comments (updating the corresponding frontend)
*/
if (!empty($user_id))
if (!empty($user_id) && $user_id > 0)
{
/** Requires mysql.inc.php */
require_once dirname(__FILE__).'/../../includes/mysql.inc.php';
require_once __DIR__.'/../../includes/mysql.inc.php';
/** Unread Comments are only valid while a User is online... for minimum external exposure. */
$sql = 'SELECT COUNT(*) AS numunread FROM comments_unread WHERE user_id IN (SELECT id FROM user WHERE activity > (NOW()-200) AND id='.$user_id.')';
$sql = 'SELECT COUNT(*) AS numunread FROM comments_unread WHERE user_id='.$user_id;
$rs = $db->fetch($db->query($sql, __FILE__, __LINE__, 'SELECT FROM comments_unread'));
/** Check if at least 1 unread comment */
$numUnreadComments = (false !== $rs['numunread'] && !empty($rs['numunread']) ? (int)$rs['numunread'] : 0);
if ($numUnreadComments > 0)
{
http_response_code(200); // Set response code 200 (OK)
header('Content-type: text/html;charset=utf-8');
printf('%d Comment%s', $numUnreadComments, ($numUnreadComments > 1 ? 's' : ''));
exit(sprintf('%d Comment%s', $numUnreadComments, ($numUnreadComments > 1 ? 's' : '')));
} else {
http_response_code(204); // Set response code 204 (OK but no Content)
exit;
}
} else {
http_response_code(403); // Set response code 403 (Forbidden)
//die('Invalid User');
exit;
}
8 changes: 4 additions & 4 deletions www/js/mobilez/browsernotifications.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var backgroundActiveCheck = 60000/4; // Refresh period, interval is passed in Miliseconds
var newNotificationCheck = 10000; // Refresh period, interval is passed in Miliseconds
var debugMode = true; // ON = true | OFF = false
var debugMode = false; // ON = true | OFF = false

function notificationsRefresh(notify) {
notify = typeof notify !== "undefined" ? notify : true; // if not otherwise specified, notify = true
Expand Down Expand Up @@ -89,7 +89,8 @@ $(document).ready(function(){
});

// Initialize the html5Notification Plugin with custom options
$.html5Notification.init({
// FIXME Disabled due to "Undefined $.html5Notification.init"
/* $.html5Notification.init({
display_message: true,
message: {
supported_browser: "Your browser does support the Notification API.",
Expand All @@ -101,6 +102,5 @@ $.html5Notification.init({
container: $("body").find("#Content"),
browser_support: $('<div class="DismissMessage AlertMessage" />')
}
})
}); */
if (debugMode) console.log("container: " + $("#Content").length);
;
2 changes: 2 additions & 0 deletions www/js/zorg.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ function updateOnlineuser(elementId, displayFormat)
var oldOnlineUserHtml = domElement.innerHTML;
var xhr = new XMLHttpRequest();
xhr.open('GET', '/js/ajax/get-onlineuser.php?style='+displayFormat);
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.onload = function() {
//console.info(xhr.responseText);
if (xhr.status === 200 || xhr.status === 204)
Expand Down Expand Up @@ -202,6 +203,7 @@ function updateUnreadComments()
let unreadsForUser = parseInt(unreadsContainer.dataset.userid);
var xhr = new XMLHttpRequest();
xhr.open('GET', '/js/ajax/get-unreadcomments.php?user='+unreadsForUser);
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.onload = function() {
//console.info(xhr.responseText);
if (xhr.status === 200)
Expand Down

0 comments on commit f10957c

Please sign in to comment.