Skip to content
Snippets Groups Projects
Commit cb8947e7 authored by Moritz Strohm's avatar Moritz Strohm
Browse files

fix for BIESt #1064

Merge request studip/studip!642
parent 70be627f
No related branches found
No related tags found
No related merge requests found
Showing with 137 additions and 119 deletions
...@@ -41,5 +41,11 @@ abstract class ForumController extends StudipController { ...@@ -41,5 +41,11 @@ abstract class ForumController extends StudipController {
} }
$this->seminar_id = $this->getId(); $this->seminar_id = $this->getId();
$this->no_entries = false;
$this->highlight = [];
$this->highlight_topic = '';
$this->edit_posting = '';
$this->js = '';
} }
} }
...@@ -52,13 +52,18 @@ ...@@ -52,13 +52,18 @@
</td> </td>
<td class="actions"> <td class="actions">
<?= ActionMenu::get()->addLink( <?
$controller->url_for("course/forum/index/index/{$entry['last_posting']['topic_id']}#{$entry['last_posting']['topic_id']}"), $issue_id = ForumIssue::getIssueIdForThread($entry['topic_id']);
_('Zur letzten Antwort'), $action_menu = ActionMenu::get();
Icon::create('forum'), if (!empty($entry['last_posting']['topic_id'])) {
is_array($entry['last_posting']) ? ['class' => 'hidden-small-up'] : ['disabled' => ''] $action_menu->addLink(
)->condition(ForumPerm::has('edit_area', $seminar_id) && $issue_id = ForumIssue::getIssueIdForThread($entry['topic_id'])) $controller->url_for("course/forum/index/index/{$entry['last_posting']['topic_id']}#{$entry['last_posting']['topic_id']}"),
->addLink( _('Zur letzten Antwort'),
Icon::create('forum'),
is_array($entry['last_posting']) ? ['class' => 'hidden-small-up'] : ['disabled' => '']
)->condition(ForumPerm::has('edit_area', $seminar_id) && $issue_id);
}
$action_menu->addLink(
URLHelper::getURL("dispatch.php/course/topics/edit/{$issue_id}"), URLHelper::getURL("dispatch.php/course/topics/edit/{$issue_id}"),
_('Zum Ablaufplan'), _('Zum Ablaufplan'),
Icon::create('info-circle', Icon::ROLE_STATUS_RED), Icon::create('info-circle', Icon::ROLE_STATUS_RED),
...@@ -82,6 +87,7 @@ ...@@ -82,6 +87,7 @@
'onclick' => "STUDIP.Forum.deleteArea(this, '{$entry['topic_id']}'); return false;", 'onclick' => "STUDIP.Forum.deleteArea(this, '{$entry['topic_id']}'); return false;",
] ]
) ?> ) ?>
<?= $action_menu ?>
</td> </td>
</tr> </tr>
<? if (is_array($entry['last_posting'])) : ?> <? if (is_array($entry['last_posting']) && count($entry['last_posting'])) : ?>
<?= _('von') ?> <?= _('von') ?>
<? if ($entry['last_posting']['anonymous']): ?> <? if (!empty($entry['last_posting']['anonymous'])): ?>
<?= _('Anonym') ?> <?= _('Anonym') ?>
<? endif; ?> <? endif; ?>
<? if (!$entry['last_posting']['anonymous'] || $entry['last_posting']['user_id'] == $GLOBALS['user']->id || $GLOBALS['perm']->have_perm('root')): ?> <? if (empty($entry['last_posting']['anonymous']) || $entry['last_posting']['user_id'] == $GLOBALS['user']->id || $GLOBALS['perm']->have_perm('root')): ?>
<a href="<?= URLHelper::getLink('dispatch.php/profile', ['username' => $entry['last_posting']['username']]) ?>"> <a href="<?= URLHelper::getLink('dispatch.php/profile', ['username' => $entry['last_posting']['username'] ?? '']) ?>">
<?= htmlReady(($temp_user = User::find($entry['last_posting']['user_id'])) ? $temp_user->getFullname() : $entry['last_posting']['user_fullname']) ?> <?= htmlReady(($temp_user = User::find($entry['last_posting']['user_id'])) ? $temp_user->getFullname() : $entry['last_posting']['user_fullname'] ?? '') ?>
</a> </a>
<? endif; ?> <? endif; ?>
<br> <br>
......
...@@ -30,10 +30,10 @@ shuffle($likes); ...@@ -30,10 +30,10 @@ shuffle($likes);
} }
$text .= '</span></span>'; $text .= '</span></span>';
} }
$text .= ' <br>'; $text .= ' <br>';
echo $text;
endif ?> endif ?>
<?= $text ?>
<!-- like/dislike links --> <!-- like/dislike links -->
<? if (!in_array($GLOBALS['user']->id, $likes)) : ?> <? if (!in_array($GLOBALS['user']->id, $likes)) : ?>
......
...@@ -5,14 +5,14 @@ ...@@ -5,14 +5,14 @@
<form action="<?= $controller->link_for('course/forum/index/add_entry') ?>" method="post" id="forum_new_entry" onSubmit="$(window).off('beforeunload')" class="default"> <form action="<?= $controller->link_for('course/forum/index/add_entry') ?>" method="post" id="forum_new_entry" onSubmit="$(window).off('beforeunload')" class="default">
<fieldset> <fieldset>
<legend> <legend>
<? if ($constraint['depth'] == 1) : ?> <? if (!empty($constraint['depth']) && ($constraint['depth'] == 1)) : ?>
<?= _('Neues Thema erstellen') ?> <?= _('Neues Thema erstellen') ?>
<? else : ?> <? else : ?>
<?= _('Antworten') ?> <?= _('Antworten') ?>
<? endif ?> <? endif ?>
</legend> </legend>
<? if ($constraint['depth'] == 1) : ?> <? if (!empty($constraint['depth']) && ($constraint['depth'] == 1)) : ?>
<? if ($GLOBALS['user']->id == 'nobody') : ?> <? if ($GLOBALS['user']->id == 'nobody') : ?>
<label> <label>
<?= _('Ihr Name') ?> <?= _('Ihr Name') ?>
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<label> <label>
<?= _('Titel') ?> <?= _('Titel') ?>
<input class="size-l" type="text" name="name" style="width: 99%" value="" <input class="size-l" type="text" name="name" style="width: 99%" value=""
<?= $constraint['depth'] == 1 ? 'required' : '' ?> placeholder="<?= _('Titel') ?>" tabindex="2"> <?= !empty($constraint['depth']) && ($constraint['depth'] == 1) ? 'required' : '' ?> placeholder="<?= _('Titel') ?>" tabindex="2">
</label> </label>
<? elseif ($GLOBALS['user']->id == 'nobody') : ?> <? elseif ($GLOBALS['user']->id == 'nobody') : ?>
<label> <label>
......
<? if (!is_array($highlight)) $highlight = []; ?>
<? $is_new = ((isset($visitdate) && $post['mkdate'] >= $visitdate) || !(isset($visitdate))) ?> <? $is_new = ((isset($visitdate) && $post['mkdate'] >= $visitdate) || !(isset($visitdate))) ?>
<? if (!$constraint) $constraint = ForumEntry::getConstraints (ForumEntry::getParentTopicId($post['topic_id'])) ?> <? if (empty($constraint)) $constraint = ForumEntry::getConstraints (ForumEntry::getParentTopicId($post['topic_id'])) ?>
<? $can_edit_closed = !ForumEntry::isClosed($constraint['topic_id']) <? $can_edit_closed = !ForumEntry::isClosed($constraint['topic_id'])
|| (ForumEntry::isClosed($constraint['topic_id']) && ForumPerm::has('edit_closed', $constraint['seminar_id'])) ?> || (ForumEntry::isClosed($constraint['topic_id']) && ForumPerm::has('edit_closed', $constraint['seminar_id'])) ?>
...@@ -12,7 +11,7 @@ ...@@ -12,7 +11,7 @@
] ?> ] ?>
<!-- Anker, um zu diesem Posting springen zu können --> <!-- Anker, um zu diesem Posting springen zu können -->
<a name="<?= $post['topic_id'] ?>"></a> <a id="<?= $post['topic_id'] ?>"></a>
<form method="post" data-topicid="<?= $post['topic_id'] ?>" action="<?= $controller->link_for('course/forum/index/update_entry/' . $post['topic_id']) ?>"> <form method="post" data-topicid="<?= $post['topic_id'] ?>" action="<?= $controller->link_for('course/forum/index/update_entry/' . $post['topic_id']) ?>">
<?= CSRFProtection::tokenTag() ?> <?= CSRFProtection::tokenTag() ?>
...@@ -132,7 +131,7 @@ ...@@ -132,7 +131,7 @@
]) ?> ]) ?>
<? endif ?> <? endif ?>
<span <?= (!$perms['edit_close'] && !$perms['remove_entry']) ? 'class="hideWhenClosed"': '' ?> <span <?= (empty($perms['edit_close']) && empty($perms['remove_entry'])) ? 'class="hideWhenClosed"': '' ?>
<?= (!$perms['edit'] && !$perms['remove_entry']) ? 'style="display: none"' : '' ?>> <?= (!$perms['edit'] && !$perms['remove_entry']) ? 'style="display: none"' : '' ?>>
<? $confirmLink = $controller->url_for('course/forum/index/delete_entry/' . $post['topic_id']) ?> <? $confirmLink = $controller->url_for('course/forum/index/delete_entry/' . $post['topic_id']) ?>
<? $confirmLinkApproved = $controller->url_for('course/forum/index/delete_entry/' . <? $confirmLinkApproved = $controller->url_for('course/forum/index/delete_entry/' .
......
...@@ -122,6 +122,8 @@ if ($section === 'index' && ForumPerm::has('pdfexport', $seminar_id)) { ...@@ -122,6 +122,8 @@ if ($section === 'index' && ForumPerm::has('pdfexport', $seminar_id)) {
Icon::create('file-pdf', 'clickable')); Icon::create('file-pdf', 'clickable'));
$sidebar->addWidget($export); $sidebar->addWidget($export);
} }
$pagechooser = null;
?> ?>
<!-- Breadcrumb navigation --> <!-- Breadcrumb navigation -->
...@@ -153,10 +155,12 @@ if ($section === 'index' && ForumPerm::has('pdfexport', $seminar_id)) { ...@@ -153,10 +155,12 @@ if ($section === 'index' && ForumPerm::has('pdfexport', $seminar_id)) {
<? endif ?> <? endif ?>
<!-- Bereiche / Themen darstellen --> <!-- Bereiche / Themen darstellen -->
<? if ($constraint['depth'] == 0) : ?> <? if (!empty($constraint['depth'])) : ?>
<?= $this->render_partial('course/forum/index/_areas') ?> <? if ($constraint['depth'] == 0) : ?>
<? elseif ($constraint['depth'] == 1) : ?> <?= $this->render_partial('course/forum/index/_areas') ?>
<?= $this->render_partial('course/forum/index/_threads') ?> <? elseif ($constraint['depth'] == 1) : ?>
<?= $this->render_partial('course/forum/index/_threads') ?>
<? endif ?>
<? endif ?> <? endif ?>
<? if (!empty($postings)) : ?> <? if (!empty($postings)) : ?>
...@@ -172,75 +176,75 @@ if ($section === 'index' && ForumPerm::has('pdfexport', $seminar_id)) { ...@@ -172,75 +176,75 @@ if ($section === 'index' && ForumPerm::has('pdfexport', $seminar_id)) {
<? endif ?> <? endif ?>
<!-- Erstellen eines neuen Elements (Kategorie, Thema, Beitrag) --> <!-- Erstellen eines neuen Elements (Kategorie, Thema, Beitrag) -->
<? if ($constraint['depth'] == 0) : ?> <? if (!empty($constraint['depth'])) : ?>
<div style="clear: right; text-align: center"> <? if ($constraint['depth'] == 0) : ?>
<div class="button-group">
<? if (ForumPerm::has('abo', $seminar_id) && $section == 'index') : ?>
<span id="abolink">
<?= $this->render_partial('course/forum/index/_abo_link', compact('constraint')) ?>
</span>
<? endif ?>
<? if (ForumPerm::has('pdfexport', $seminar_id) && $section == 'index') : ?>
<?= Studip\LinkButton::create(_('Beiträge als PDF exportieren'), $controller->url_for('course/forum/index/pdfexport'), ['target' => '_blank']) ?>
<? endif ?>
</div>
</div>
<? if ($section == 'index' && $constraint['depth'] == 0 && ForumPerm::has('add_category', $seminar_id)) : ?>
<?= $this->render_partial('course/forum/index/_new_category') ?>
<? endif ?>
<? else : ?>
<? if (!$flash['edit_entry'] && ForumPerm::has('add_entry', $seminar_id)) : ?>
<? $constraint['depth'] == 1 ? $button_face = _('Neues Thema erstellen') : $button_face = _('Antworten') ?>
<div id="new_entry_button">
<div style="clear: right; text-align: center"> <div style="clear: right; text-align: center">
<div class="button-group"> <div class="button-group">
<? if ($constraint['depth'] <= 1 || ($constraint['closed'] == 0)) : ?> <? if (ForumPerm::has('abo', $seminar_id) && $section == 'index') : ?>
<?= Studip\LinkButton::create($button_face, $controller->url_for('course/forum/index/index/'. $topic_id .'?answer=1'), <span id="abolink">
['onClick' => 'STUDIP.Forum.answerEntry(); return false;', <?= $this->render_partial('course/forum/index/_abo_link', compact('constraint')) ?>
'class' => 'hideWhenClosed',]) ?> </span>
<? endif ?>
<? if ($constraint['depth'] > 1 && ($constraint['closed'] == 1)) : ?>
<?= Studip\LinkButton::create($button_face, $controller->url_for('course/forum/index/index/' . $topic_id. '?answer=1'),
['onClick' => 'STUDIP.Forum.answerEntry(); return false;',
'class' => 'hideWhenClosed',
'style' => 'display:none;'
]) ?>
<? endif ?>
<? if (ForumPerm::has('close_thread', $seminar_id) && $constraint['depth'] > 1) : ?>
<? if ($constraint['closed'] == 0): ?>
<?= Studip\LinkButton::create(_('Thema schließen'),
$controller->url_for('course/forum/index/close_thread/' . $topic_id .'/'. $topic_id .'/'. ForumHelpers::getPage()), [
'onClick' => 'STUDIP.Forum.closeThreadFromThread("'. $topic_id .'"); return false;',
'class' => 'closeButtons']
) ?>
<? else: ?>
<?= Studip\LinkButton::create(_('Thema öffnen'),
$controller->url_for('course/forum/index/open_thread/' . $topic_id .'/'. $topic_id .'/'. ForumHelpers::getPage()), [
'onClick' => 'STUDIP.Forum.openThreadFromThread("'. $topic_id .'"); return false;',
'class' => 'closeButtons']
) ?>
<? endif ?>
<? endif ?>
<? if ($constraint['depth'] > 0 && ForumPerm::has('abo', $seminar_id)) : ?>
<span id="abolink">
<?= $this->render_partial('course/forum/index/_abo_link', compact('constraint')) ?>
</span>
<? endif ?> <? endif ?>
<? if (ForumPerm::has('pdfexport', $seminar_id)) : ?> <? if (ForumPerm::has('pdfexport', $seminar_id) && $section == 'index') : ?>
<?= Studip\LinkButton::create(_('Beiträge als PDF exportieren'), $controller->url_for('course/forum/index/pdfexport/' . $topic_id), ['target' => '_blank']) ?> <?= Studip\LinkButton::create(_('Beiträge als PDF exportieren'), $controller->url_for('course/forum/index/pdfexport'), ['target' => '_blank']) ?>
<? endif ?> <? endif ?>
</div> </div>
</div> </div>
</div> <? if ($section == 'index' && $constraint['depth'] == 0 && ForumPerm::has('add_category', $seminar_id)) : ?>
<?= $this->render_partial('course/forum/index/_new_category') ?>
<? endif ?>
<? else : ?>
<? if (!$flash['edit_entry'] && ForumPerm::has('add_entry', $seminar_id)) : ?>
<? $constraint['depth'] == 1 ? $button_face = _('Neues Thema erstellen') : $button_face = _('Antworten') ?>
<div id="new_entry_button">
<div style="clear: right; text-align: center">
<div class="button-group">
<? if ($constraint['depth'] <= 1 || ($constraint['closed'] == 0)) : ?>
<?= Studip\LinkButton::create($button_face, $controller->url_for('course/forum/index/index/'. $topic_id .'?answer=1'),
['onClick' => 'STUDIP.Forum.answerEntry(); return false;',
'class' => 'hideWhenClosed',]) ?>
<? endif ?>
<? if ($constraint['depth'] > 1 && ($constraint['closed'] == 1)) : ?>
<?= Studip\LinkButton::create($button_face, $controller->url_for('course/forum/index/index/' . $topic_id. '?answer=1'),
['onClick' => 'STUDIP.Forum.answerEntry(); return false;',
'class' => 'hideWhenClosed',
'style' => 'display:none;'
]) ?>
<? endif ?>
<? if (ForumPerm::has('close_thread', $seminar_id) && $constraint['depth'] > 1) : ?>
<? if ($constraint['closed'] == 0): ?>
<?= Studip\LinkButton::create(_('Thema schließen'),
$controller->url_for('course/forum/index/close_thread/' . $topic_id .'/'. $topic_id .'/'. ForumHelpers::getPage()), [
'onClick' => 'STUDIP.Forum.closeThreadFromThread("'. $topic_id .'"); return false;',
'class' => 'closeButtons']
) ?>
<? else: ?>
<?= Studip\LinkButton::create(_('Thema öffnen'),
$controller->url_for('course/forum/index/open_thread/' . $topic_id .'/'. $topic_id .'/'. ForumHelpers::getPage()), [
'onClick' => 'STUDIP.Forum.openThreadFromThread("'. $topic_id .'"); return false;',
'class' => 'closeButtons']
) ?>
<? endif ?>
<? endif ?>
<? if ($constraint['depth'] > 0 && ForumPerm::has('abo', $seminar_id)) : ?>
<span id="abolink">
<?= $this->render_partial('course/forum/index/_abo_link', compact('constraint')) ?>
</span>
<? endif ?>
<? if (ForumPerm::has('pdfexport', $seminar_id)) : ?>
<?= Studip\LinkButton::create(_('Beiträge als PDF exportieren'), $controller->url_for('course/forum/index/pdfexport/' . $topic_id), ['target' => '_blank']) ?>
<? endif ?>
</div>
</div>
</div>
<? endif ?>
<? endif ?> <? endif ?>
<? endif ?> <? endif ?>
<? if ( (ForumPerm::has('add_area', $this->seminar_id)) <? if ( (ForumPerm::has('add_area', $this->seminar_id))
......
...@@ -420,7 +420,7 @@ class ForumEntry implements PrivacyObject ...@@ -420,7 +420,7 @@ class ForumEntry implements PrivacyObject
'user_id' => $data['user_id'], 'user_id' => $data['user_id'],
'raw_title' => $data['name'], 'raw_title' => $data['name'],
'raw_description' => ForumEntry::killEdit($data['content']), 'raw_description' => ForumEntry::killEdit($data['content']),
'fav' => ($data['fav'] == 'fav'), 'fav' => (!empty($data['fav']) && ($data['fav'] == 'fav')),
'depth' => $data['depth'], 'depth' => $data['depth'],
'anonymous' => $data['anonymous'], 'anonymous' => $data['anonymous'],
'closed' => $data['closed'], 'closed' => $data['closed'],
...@@ -550,7 +550,9 @@ class ForumEntry implements PrivacyObject ...@@ -550,7 +550,9 @@ class ForumEntry implements PrivacyObject
*/ */
public static function getLastPostings($postings) public static function getLastPostings($postings)
{ {
foreach ($postings as $key => $posting) { foreach ($postings as $key => $posting)
{
$last_posting = [];
if ($data = ForumEntry::getLatestPosting($posting['topic_id'])) { if ($data = ForumEntry::getLatestPosting($posting['topic_id'])) {
$last_posting['topic_id'] = $data['topic_id']; $last_posting['topic_id'] = $data['topic_id'];
...@@ -574,7 +576,7 @@ class ForumEntry implements PrivacyObject ...@@ -574,7 +576,7 @@ class ForumEntry implements PrivacyObject
$postings[$key]['last_posting'] = $last_posting; $postings[$key]['last_posting'] = $last_posting;
if (!$postings[$key]['last_unread'] = ForumEntry::getLastUnread($posting['topic_id'])) { if (!$postings[$key]['last_unread'] = ForumEntry::getLastUnread($posting['topic_id'])) {
$postings[$key]['last_unread'] = $last_posting['topic_id']; $postings[$key]['last_unread'] = $last_posting['topic_id'] ?? '';
} }
$postings[$key]['num_postings'] = ForumEntry::countEntries($posting['topic_id']); $postings[$key]['num_postings'] = ForumEntry::countEntries($posting['topic_id']);
...@@ -735,7 +737,7 @@ class ForumEntry implements PrivacyObject ...@@ -735,7 +737,7 @@ class ForumEntry implements PrivacyObject
'user_id' => $data['user_id'], 'user_id' => $data['user_id'],
'raw_title' => $data['name'], 'raw_title' => $data['name'],
'raw_description' => ForumEntry::killEdit($data['content']), 'raw_description' => ForumEntry::killEdit($data['content']),
'fav' => ($data['fav'] == 'fav'), 'fav' => (!empty($data['fav']) && $data['fav'] == 'fav'),
'depth' => $data['depth'], 'depth' => $data['depth'],
'seminar_id' => $data['seminar_id'] 'seminar_id' => $data['seminar_id']
]; ];
...@@ -906,7 +908,7 @@ class ForumEntry implements PrivacyObject ...@@ -906,7 +908,7 @@ class ForumEntry implements PrivacyObject
{ {
static $entries; static $entries;
if (!$entries[$user_id]) { if (empty($entries[$user_id])) {
$stmt = DBManager::get()->prepare("SELECT COUNT(*) $stmt = DBManager::get()->prepare("SELECT COUNT(*)
FROM forum_entries FROM forum_entries
WHERE user_id = ? AND seminar_id = IFNULL(?, seminar_id)"); WHERE user_id = ? AND seminar_id = IFNULL(?, seminar_id)");
...@@ -953,7 +955,7 @@ class ForumEntry implements PrivacyObject ...@@ -953,7 +955,7 @@ class ForumEntry implements PrivacyObject
VALUES (? ,?, ?, ?, ?, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), ?, ?, ?, ?, ?, ?)"); VALUES (? ,?, ?, ?, ?, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), ?, ?, ?, ?, ?, ?)");
$stmt->execute([$data['topic_id'], $data['seminar_id'], $data['user_id'], $stmt->execute([$data['topic_id'], $data['seminar_id'], $data['user_id'],
$data['name'], transformBeforeSave($data['content']), $data['author'], $data['author_host'], $data['name'], transformBeforeSave($data['content']), $data['author'], $data['author_host'],
$constraint['rgt'], $constraint['rgt'] + 1, $constraint['depth'] + 1, $data['anonymous'] ? : 0]); $constraint['rgt'], $constraint['rgt'] + 1, $constraint['depth'] + 1, $data['anonymous'] ?? 0]);
// update "latest_chdate" for easier sorting of actual threads // update "latest_chdate" for easier sorting of actual threads
DBManager::get()->exec("UPDATE forum_entries SET latest_chdate = UNIX_TIMESTAMP() DBManager::get()->exec("UPDATE forum_entries SET latest_chdate = UNIX_TIMESTAMP()
......
...@@ -13,11 +13,11 @@ ...@@ -13,11 +13,11 @@
*/ */
class ForumLike { class ForumLike {
/** /**
* Set the posting denoted by the passed topic_id as liked for the * Set the posting denoted by the passed topic_id as liked for the
* currently logged in user * currently logged in user
* *
* @param string $topic_id * @param string $topic_id
*/ */
static function like($topic_id) { static function like($topic_id) {
...@@ -25,64 +25,66 @@ class ForumLike { ...@@ -25,64 +25,66 @@ class ForumLike {
forum_likes (topic_id, user_id) forum_likes (topic_id, user_id)
VALUES (?, ?)"); VALUES (?, ?)");
$stmt->execute([$topic_id, $GLOBALS['user']->id]); $stmt->execute([$topic_id, $GLOBALS['user']->id]);
// get posting owner // get posting owner
$data = ForumEntry::getConstraints($topic_id); $data = ForumEntry::getConstraints($topic_id);
// notify owner of posting about the like // notify owner of posting about the like
setTempLanguage($data['user_id']); setTempLanguage($data['user_id']);
$notification = get_fullname($GLOBALS['user']->id) . _(' gefällt einer deiner Forenbeiträge!'); $notification = get_fullname($GLOBALS['user']->id) . _(' gefällt einer deiner Forenbeiträge!');
restoreLanguage(); restoreLanguage();
PersonalNotifications::add( PersonalNotifications::add(
$data['user_id'], URLHelper::getURL('dispatch.php/course/forum/index/index/' . $topic_id .'?highlight_topic='. $topic_id .'#'. $topic_id), $data['user_id'],
$notification, $topic_id, URLHelper::getURL('dispatch.php/course/forum/index/index/' . $topic_id .'?highlight_topic='. $topic_id .'#'. $topic_id),
$notification,
$topic_id,
Icon::create('forum', 'clickable') Icon::create('forum', 'clickable')
); );
} }
/** /**
* Revoke the liking of the posting denoted by the passed topic_id for the * Revoke the liking of the posting denoted by the passed topic_id for the
* currently logged in user * currently logged in user
* *
* @param string $topic_id * @param string $topic_id
*/ */
static function dislike($topic_id) { static function dislike($topic_id) {
$stmt = DBManager::get()->prepare("DELETE FROM forum_likes $stmt = DBManager::get()->prepare("DELETE FROM forum_likes
WHERE topic_id = ? AND user_id = ?"); WHERE topic_id = ? AND user_id = ?");
$stmt->execute([$topic_id, $GLOBALS['user']->id]); $stmt->execute([$topic_id, $GLOBALS['user']->id]);
} }
/** /**
* Get the user_id for all likers of the topic denoted by the passed id * Get the user_id for all likers of the topic denoted by the passed id
* *
* @param string $topic_id * @param string $topic_id
* @return array an array of user_id's * @return array an array of user_id's
*/ */
static function getLikes($topic_id) { static function getLikes($topic_id) {
$stmt = DBManager::get()->prepare("SELECT $stmt = DBManager::get()->prepare("SELECT
auth_user_md5.user_id FROM forum_likes auth_user_md5.user_id FROM forum_likes
LEFT JOIN auth_user_md5 USING (user_id) LEFT JOIN auth_user_md5 USING (user_id)
LEFT JOIN user_info USING (user_id) LEFT JOIN user_info USING (user_id)
WHERE topic_id = ?"); WHERE topic_id = ?");
$stmt->execute([$topic_id]); $stmt->execute([$topic_id]);
return $stmt->fetchAll(PDO::FETCH_COLUMN); return $stmt->fetchAll(PDO::FETCH_COLUMN);
} }
/** /**
* count the number of likes the user has received - system-wide * count the number of likes the user has received - system-wide
* *
* @staticvar type $entries * @staticvar type $entries
* @param string $user_id the user's id to count the received likes for * @param string $user_id the user's id to count the received likes for
* *
* @return int the number of likes received * @return int the number of likes received
*/ */
static function receivedForUser($user_id) static function receivedForUser($user_id)
{ {
static $entries; static $entries;
if (!$entries[$user_id]) { if (empty($entries[$user_id])) {
$stmt = DBManager::get()->prepare("SELECT COUNT(*) $stmt = DBManager::get()->prepare("SELECT COUNT(*)
FROM forum_entries FROM forum_entries
LEFT JOIN forum_likes USING (topic_id) LEFT JOIN forum_likes USING (topic_id)
......
...@@ -58,7 +58,7 @@ class ForumPerm { ...@@ -58,7 +58,7 @@ class ForumPerm {
} }
// get the status for the user in the passed seminar // get the status for the user in the passed seminar
if (!$permissions[$seminar_id][$user_id]) { if (empty($permissions[$seminar_id][$user_id])) {
$permissions[$seminar_id][$user_id] = $GLOBALS['perm']->get_studip_perm($seminar_id, $user_id); $permissions[$seminar_id][$user_id] = $GLOBALS['perm']->get_studip_perm($seminar_id, $user_id);
} }
...@@ -155,7 +155,7 @@ class ForumPerm { ...@@ -155,7 +155,7 @@ class ForumPerm {
{ {
static $perms = []; static $perms = [];
if (!$perms[$topic_id]) { if (empty($perms[$topic_id])) {
// find out if the posting is the last in the thread // find out if the posting is the last in the thread
$constraints = ForumEntry::getConstraints($topic_id); $constraints = ForumEntry::getConstraints($topic_id);
......
...@@ -157,6 +157,6 @@ class ForumVisit { ...@@ -157,6 +157,6 @@ class ForumVisit {
static function getVisit($seminar_id) static function getVisit($seminar_id)
{ {
$visit = self::getVisitDates($seminar_id); $visit = self::getVisitDates($seminar_id);
return $visit['visitdate']; return $visit['visitdate'] ?? 0;
} }
} }
...@@ -49,8 +49,8 @@ class SmileyFormat extends TextFormat ...@@ -49,8 +49,8 @@ class SmileyFormat extends TextFormat
static function short($markup, $matches) static function short($markup, $matches)
{ {
$smileys = Smiley::getShort(); $smileys = Smiley::getShort();
$name = $smileys[$matches[2]]; $name = $smileys[$matches[2]] ?? '';
return isset($name) return $name
? $matches[1] . Smiley::getByName($name)->getImageTag() . $matches[3] ? $matches[1] . Smiley::getByName($name)->getImageTag() . $matches[3]
: $matches[0]; : $matches[0];
} }
......
...@@ -55,13 +55,13 @@ class PersonalNotifications extends SimpleORMap ...@@ -55,13 +55,13 @@ class PersonalNotifications extends SimpleORMap
protected $unseen = null; protected $unseen = null;
protected function cbExpireCache($notification) protected function cbExpireCache()
{ {
$query = "SELECT user_id $query = "SELECT user_id
FROM personal_notifications_user FROM personal_notifications_user
WHERE personal_notification_id = :id"; WHERE personal_notification_id = :id";
$statement = DBManager::get()->prepare($query); $statement = DBManager::get()->prepare($query);
$statement->bindValue(':id', $notification->id); $statement->bindValue(':id', $this->id);
$statement->execute(); $statement->execute();
$user_ids = $statement->fetchAll(PDO::FETCH_COLUMN); $user_ids = $statement->fetchAll(PDO::FETCH_COLUMN);
......
...@@ -32,9 +32,8 @@ class AutoNavigation extends Navigation ...@@ -32,9 +32,8 @@ class AutoNavigation extends Navigation
// if URL is set, try to guess whether active or not // if URL is set, try to guess whether active or not
if (isset($url)) { if (isset($url)) {
list($request_path, $query) = explode('?', Request::path()); $request_path = explode('?', Request::path())[0];
list($request_url, $query) = explode('?', Request::url()); $request_url = explode('?', Request::url())[0];
list($url, $query) = explode('?', $url);
if (!preg_match('%^[a-z]+:%', $url) && $url[0] !== '/') { if (!preg_match('%^[a-z]+:%', $url) && $url[0] !== '/') {
$url = $GLOBALS['CANONICAL_RELATIVE_PATH_STUDIP'].$url; $url = $GLOBALS['CANONICAL_RELATIVE_PATH_STUDIP'].$url;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment