From e4e337942d37ec4bedb1fbc273b31a44ea1768ec Mon Sep 17 00:00:00 2001
From: Roman Kelesidis
Date: Mon, 20 Feb 2023 18:50:03 +0700
Subject: [PATCH] Added user birthday icon in profile
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Добавляет иконку тортика в профиль.
До этого иконка выводилась только в viewtopic, теперь же она добавляется в viewprofile
Для универсальности написал отдельную функцию которая принимает в себя $user_birthday и $user_id.
---
library/includes/functions.php | 18 ++++++++++++++++++
library/includes/ucp/viewprofile.php | 1 +
.../templates/default/usercp_viewprofile.tpl | 1 +
viewtopic.php | 6 +-----
4 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/library/includes/functions.php b/library/includes/functions.php
index 17de5ece5..5914932c4 100644
--- a/library/includes/functions.php
+++ b/library/includes/functions.php
@@ -2092,3 +2092,21 @@ function clean_tor_dirname($dirname)
{
return str_replace(array('[', ']', '<', '>', "'"), array('[', ']', '<', '>', '''), $dirname);
}
+
+/**
+ * Get birthday icon
+ *
+ * @param $user_birthday
+ * @param $user_id
+ * @return string
+ */
+function user_birthday_icon($user_birthday, $user_id): string
+{
+ global $bb_cfg, $images, $lang;
+
+ $current_date = bb_date(TIMENOW, 'md', false);
+ $user_birthday = ($user_id != GUEST_UID && !empty($user_birthday) && $user_birthday != '1900-01-01')
+ ? date('md', strtotime($user_birthday)) : false;
+
+ return ($bb_cfg['birthday_enabled'] && $current_date == $user_birthday) ? '
' : '';
+}
diff --git a/library/includes/ucp/viewprofile.php b/library/includes/ucp/viewprofile.php
index e711f977b..deb529e62 100644
--- a/library/includes/ucp/viewprofile.php
+++ b/library/includes/ucp/viewprofile.php
@@ -99,6 +99,7 @@ $template->assign_vars(array(
'USER_POINTS' => $profiledata['user_points'],
'GENDER' => ($bb_cfg['gender']) ? $lang['GENDER_SELECT'][$profiledata['user_gender']] : '',
'BIRTHDAY' => ($bb_cfg['birthday_enabled'] && !empty($profiledata['user_birthday']) && $profiledata['user_birthday'] != '1900-01-01') ? $profiledata['user_birthday'] : '',
+ 'BIRTHDAY_ICON' => user_birthday_icon($profiledata['user_birthday'], $profiledata['user_id']),
'AGE' => ($bb_cfg['birthday_enabled'] && !empty($profiledata['user_birthday']) && $profiledata['user_birthday'] != '1900-01-01') ? birthday_age($profiledata['user_birthday']) : '',
'L_VIEWING_PROFILE' => sprintf($lang['VIEWING_USER_PROFILE'], $profiledata['username']),
diff --git a/styles/templates/default/usercp_viewprofile.tpl b/styles/templates/default/usercp_viewprofile.tpl
index 56056f379..e5ee8dd84 100644
--- a/styles/templates/default/usercp_viewprofile.tpl
+++ b/styles/templates/default/usercp_viewprofile.tpl
@@ -221,6 +221,7 @@ ajax.callback.gen_passkey = function(data){
{RANK_IMAGE}
+ {BIRTHDAY_ICON}
{L_CONTACT} {USERNAME}
diff --git a/viewtopic.php b/viewtopic.php
index ac56341fd..10a34225d 100644
--- a/viewtopic.php
+++ b/viewtopic.php
@@ -566,13 +566,9 @@ if ($topic_has_poll) {
$prev_post_time = $max_post_time = 0;
-$this_date = bb_date(TIMENOW, 'md', false);
-
for ($i = 0; $i < $total_posts; $i++) {
$poster_id = $postrow[$i]['user_id'];
$poster = ($poster_id == GUEST_UID) ? $lang['GUEST'] : $postrow[$i]['username'];
- $poster_birthday = ($poster_id != GUEST_UID && !empty($postrow[$i]['user_birthday']) && $postrow[$i]['user_birthday'] != '1900-01-01')
- ? date('md', strtotime($postrow[$i]['user_birthday'])) : '';
$post_date = bb_date($postrow[$i]['post_time'], $bb_cfg['post_date_format']);
$max_post_time = max($max_post_time, $postrow[$i]['post_time']);
$poster_posts = ($poster_id != GUEST_UID) ? $postrow[$i]['user_posts'] : '';
@@ -732,7 +728,7 @@ for ($i = 0; $i < $total_posts; $i++) {
'DELETE' => $delpost_btn,
'IP' => $ip_btn,
- 'POSTER_BIRTHDAY' => ($bb_cfg['birthday_enabled'] && $this_date == $poster_birthday) ? '
' : '',
+ 'POSTER_BIRTHDAY' => user_birthday_icon($postrow[$i]['user_birthday'], $postrow[$i]['user_id']),
'MC_COMMENT' => ($mc_type) ? bbcode2html($mc_comment) : '',
'MC_BBCODE' => ($mc_type) ? $mc_comment : '',