Skip to content

Commit

Permalink
#1040 Split of notifications from profile
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick committed Jan 13, 2015
1 parent 368928c commit 6605296
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 87 deletions.
6 changes: 3 additions & 3 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function process_form(the_form) {
if ($luna_config['o_notification_flyout'] == 1) {
if ($num_notifications == '0') {
$notificon = '<span class="fa fa-circle-o"></span>';
$ind_notification[] = '<li><a href="me.php?section=notifications&id='.$luna_user['id'].'">No new notifications</a></li>';
$ind_notification[] = '<li><a href="notifications.php?id='.$luna_user['id'].'">No new notifications</a></li>';
} else {
$notificon = $num_notifications.' <span class="fa fa-circle"></span>';

Expand All @@ -107,7 +107,7 @@ function process_form(the_form) {
<li class="divider"></li>
'.$notifications.'
<li class="divider"></li>
<li><a class="pull-right" href="me.php?section=notifications&id='.$luna_user['id'].'">More <i class="fa fa-arrow-right"></i></a></li>
<li><a class="pull-right" href="notifications.php?id='.$luna_user['id'].'">More <i class="fa fa-arrow-right"></i></a></li>
</ul>
</li>';
} else {
Expand All @@ -116,7 +116,7 @@ function process_form(the_form) {
else
$notificon = $num_notifications.' <span class="fa fa-circle"></span>';

$notification_menu_item = '<li><a href="me.php?section=notifications&id='.$luna_user['id'].'">'.$notificon.'<span class="visible-xs-inline"> Notifications</span></a></li>';
$notification_menu_item = '<li><a href="notifications.php?id='.$luna_user['id'].'">'.$notificon.'<span class="visible-xs-inline"> Notifications</span></a></li>';
}

// Generate navigation items
Expand Down
4 changes: 2 additions & 2 deletions include/me_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ function load_me_nav($page = '') {

?>
<div class="list-group">
<a class="<?php if ($page == 'profile') echo 'active'; ?> list-group-item" href="me.php?section=view&amp;id=<?php echo $id ?>">Profile</a>
<a class="<?php if ($page == 'notifications') echo 'active'; ?> list-group-item" href="me.php?section=notifications&amp;id=<?php echo $id ?>">Notifications</a>
<a class="<?php if ($page == 'profile') echo 'active'; ?> list-group-item" href="me.php?id=<?php echo $id ?>">Profile</a>
<a class="<?php if ($page == 'notifications') echo 'active'; ?> list-group-item" href="notifications.php?id=<?php echo $id ?>">Notifications</a>
<?php if ($luna_user['id'] == $id && !$luna_user['is_guest'] || ($luna_user['g_id'] == FORUM_ADMIN || ($luna_user['g_moderator'] == '1' && $luna_user['g_mod_ban_users'] == '1')) || ($luna_user['g_id'] == FORUM_ADMIN || ($luna_user['g_moderator'] == '1' && $luna_user['g_mod_ban_users'] == '1'))): ?>
<a class="<?php if ($page == 'settings') echo 'active'; ?> list-group-item" href="settings.php?id=<?php echo $id ?>"><?php echo $lang['Settings'] ?></a>
<?php endif; ?>
Expand Down
2 changes: 1 addition & 1 deletion include/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Version {
const FORUM_VERSION = '0.2-beta';

// The Luna Core version
const FORUM_CORE_VERSION = '0.2.3607';
const FORUM_CORE_VERSION = '0.2.3609';

// The database version number, every change in the database requires this number to go one up
const FORUM_DB_VERSION = '87.14';
Expand Down
81 changes: 14 additions & 67 deletions me.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,10 @@
require FORUM_ROOT.'include/utf8/ucwords.php'; // utf8_ucwords needs utf8_substr_replace
require FORUM_ROOT.'include/utf8/strcasecmp.php';

$action = isset($_GET['action']) ? $_GET['action'] : null;
$type = isset($_GET['type']) ? $_GET['type'] : null;
$section = isset($_GET['section']) ? $_GET['section'] : null;
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
if ($id < 2)
message($lang['Bad request'], false, '404 Not Found');

if ($action != 'change_pass' || !isset($_GET['key'])) {
if ($luna_user['g_read_board'] == '0')
message($lang['No view'], false, '403 Forbidden');
else if ($luna_user['g_view_users'] == '0' && ($luna_user['is_guest'] || $luna_user['id'] != $id))
message($lang['No permission'], false, '403 Forbidden');
}

$result = $db->query('SELECT u.username, u.email, u.title, u.realname, u.url, u.facebook, u.msn, u.twitter, u.google, u.location, u.signature, u.disp_topics, u.disp_posts, u.email_setting, u.notify_with_post, u.auto_notify, u.show_smilies, u.show_img, u.show_img_sig, u.show_avatars, u.show_sig, u.timezone, u.dst, u.language, u.style, u.num_posts, u.last_post, u.registered, u.registration_ip, u.admin_note, u.date_format, u.time_format, u.last_visit, u.color, g.g_id, g.g_user_title, g.g_moderator FROM '.$db->prefix.'users AS u LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
if (!$db->num_rows($result))
message($lang['Bad request'], false, '404 Not Found');
Expand Down Expand Up @@ -90,9 +80,9 @@
$email_field = '<a class="btn btn-default btn-block" href="misc.php?email='.$id.'"><span class="fa fa-send-o"></span> '.$lang['Send email'].'</a>';
else
$email_field = '';
if ($email_field != '') {

if ($email_field != '')
$email_field;
}

$user_messaging = array();

Expand Down Expand Up @@ -122,59 +112,16 @@
$parsed_signature = parse_signature($user['signature']);
}

if ($action == 'newnoti') {
if ($type == 'windows') {
new_notification('2', 'index.php', 'Windows 8.1 is recent', 'fa-windows');
} elseif ($type == 'comment') {
new_notification('2', 'index.php', 'Someone made a comment on your topic', 'fa-comment');
} elseif ($type == 'check') {
new_notification('2', 'index.php', 'Check this out', 'fa-check');
} elseif ($type == 'version') {
new_notification('2', 'index.php', 'You are using Luna '.$luna_config['o_core_version'].'! Awesome!', 'fa-moon-o');
} elseif ($type == 'cogs') {
new_notification('2', 'index.php', 'This icon usualy indicates settings, not now through...', 'fa-cogs');
}
$last_post = format_time($user['last_post']);

redirect('me.php?section=notifications&amp;id='.$id);
} else if ($action == 'readnoti') {
$db->query('UPDATE '.$db->prefix.'notifications SET viewed = 1 WHERE user_id = '.$id.' AND viewed = 0') or error('Unable to update the notification status', __FILE__, __LINE__, $db->error());
confirm_referrer('me.php');

redirect('me.php?section=notifications&amp;id='.$id);
} else if ($action == 'delnoti') {
$db->query('DELETE FROM '.$db->prefix.'notifications WHERE viewed = 1') or error('Unable to remove notifications', __FILE__, __LINE__, $db->error());
confirm_referrer('me.php');

redirect('me.php?section=notifications&amp;id='.$id);
} else {

$result = $db->query('SELECT u.id, u.username, u.email, u.title, u.realname, u.url, u.facebook, u.msn, u.twitter, u.google, u.location, u.signature, u.disp_topics, u.disp_posts, u.email_setting, u.notify_with_post, u.auto_notify, u.show_smilies, u.show_img, u.show_img_sig, u.show_avatars, u.show_sig, u.timezone, u.dst, u.language, u.style, u.color, u.num_posts, u.last_post, u.registered, u.registration_ip, u.admin_note, u.date_format, u.time_format, u.last_visit, g.g_id, g.g_user_title, g.g_moderator FROM '.$db->prefix.'users AS u LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
if (!$db->num_rows($result))
message($lang['Bad request'], false, '404 Not Found');

$user = $db->fetch_assoc($result);

$last_post = format_time($user['last_post']);

if ($user['signature'] != '') {
$parsed_signature = parse_signature($user['signature']);
}

// View or edit?
if (!$section || $section == 'view') {
$page_title = array(luna_htmlspecialchars($luna_config['o_board_title']).' / '.$lang['Profile']);
define('FORUM_ACTIVE_PAGE', 'me');
require load_page('header.php');
require load_page('profile.php');
} else if ($section == 'notifications') {

$page_title = array(luna_htmlspecialchars($luna_config['o_board_title']).' / '.$lang['Profile']);
define('FORUM_ACTIVE_PAGE', 'me');
require load_page('header.php');
require load_page('notifications.php');
} else {
message($lang['Bad request'], false, '404 Not Found');
}

require load_page('footer.php');
}
if ($user['signature'] != '') {
$parsed_signature = parse_signature($user['signature']);
}

// View or edit?
$page_title = array(luna_htmlspecialchars($luna_config['o_board_title']).' / '.$lang['Profile']);
define('FORUM_ACTIVE_PAGE', 'me');
require load_page('header.php');
require load_page('profile.php');

require load_page('footer.php');
69 changes: 69 additions & 0 deletions notifications.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

/*
* Copyright (C) 2013-2015 Luna
* Based on code by FluxBB copyright (C) 2008-2012 FluxBB
* Based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
* Licensed under GPLv3 (http://modernbb.be/license.php)
*/

define('FORUM_ROOT', dirname(__FILE__).'/');
require FORUM_ROOT.'include/common.php';

// Load the me functions script
require FORUM_ROOT.'include/me_functions.php';

// Include UTF-8 function
require FORUM_ROOT.'include/utf8/substr_replace.php';
require FORUM_ROOT.'include/utf8/ucwords.php'; // utf8_ucwords needs utf8_substr_replace
require FORUM_ROOT.'include/utf8/strcasecmp.php';

$action = isset($_GET['action']) ? $_GET['action'] : null;
$type = isset($_GET['type']) ? $_GET['type'] : null;
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
if ($id < 2)
message($lang['Bad request'], false, '404 Not Found');

$result = $db->query('SELECT u.username, u.email, u.title, u.realname, u.url, u.facebook, u.msn, u.twitter, u.google, u.location, u.signature, u.disp_topics, u.disp_posts, u.email_setting, u.notify_with_post, u.auto_notify, u.show_smilies, u.show_img, u.show_img_sig, u.show_avatars, u.show_sig, u.timezone, u.dst, u.language, u.style, u.num_posts, u.last_post, u.registered, u.registration_ip, u.admin_note, u.date_format, u.time_format, u.last_visit, u.color, g.g_id, g.g_user_title, g.g_moderator FROM '.$db->prefix.'users AS u LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
if (!$db->num_rows($result))
message($lang['Bad request'], false, '404 Not Found');

$user = $db->fetch_assoc($result);

$user_username = luna_htmlspecialchars($user['username']);
$avatar_field = generate_avatar_markup($id);
$avatar_user_card = draw_user_avatar($id, 'visible-lg-block');

if ($action == 'newnoti') {
if ($type == 'windows') {
new_notification('2', 'index.php', 'Windows 8.1 is recent', 'fa-windows');
} elseif ($type == 'comment') {
new_notification('2', 'index.php', 'Someone made a comment on your topic', 'fa-comment');
} elseif ($type == 'check') {
new_notification('2', 'index.php', 'Check this out', 'fa-check');
} elseif ($type == 'version') {
new_notification('2', 'index.php', 'You are using Luna '.$luna_config['o_core_version'].'! Awesome!', 'fa-moon-o');
} elseif ($type == 'cogs') {
new_notification('2', 'index.php', 'This icon usualy indicates settings, not now through...', 'fa-cogs');
}

redirect('notifications.php?id='.$id);
} else if ($action == 'readnoti') {
$db->query('UPDATE '.$db->prefix.'notifications SET viewed = 1 WHERE user_id = '.$id.' AND viewed = 0') or error('Unable to update the notification status', __FILE__, __LINE__, $db->error());
confirm_referrer('me.php');

redirect('notifications.php?id='.$id);
} else if ($action == 'delnoti') {
$db->query('DELETE FROM '.$db->prefix.'notifications WHERE viewed = 1') or error('Unable to remove notifications', __FILE__, __LINE__, $db->error());
confirm_referrer('me.php');

redirect('notifications.php?id='.$id);
}

$page_title = array(luna_htmlspecialchars($luna_config['o_board_title']).' / '.$lang['Profile']);
define('FORUM_ACTIVE_PAGE', 'me');
require load_page('header.php');

require load_page('notifications.php');

require load_page('footer.php');
2 changes: 1 addition & 1 deletion register.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
$mail_message = str_replace('<username>', $username, $mail_message);
$mail_message = str_replace('<email>', $email1, $mail_message);
$mail_message = str_replace('<profile_url>', get_base_url().'/me.php?id='.$new_uid, $mail_message);
$mail_message = str_replace('<admin_url>', get_base_url().'/me.php?section=admin&id='.$new_uid, $mail_message);
$mail_message = str_replace('<admin_url>', get_base_url().'/settings.php?id='.$new_uid, $mail_message);
$mail_message = str_replace('<board_mailer>', $luna_config['o_board_title'], $mail_message);

luna_mail($luna_config['o_mailing_list'], $mail_subject, $mail_message);
Expand Down
26 changes: 13 additions & 13 deletions style/Sunrise/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
exit;

// Show notifications
$result = $db->query('SELECT COUNT(id) FROM '.$db_prefix.'notifications WHERE viewed = 0 AND user_id = '.$user['id']) or error ('Unable to load notifications', __FILE__, __LINE__, $db->error());
$result = $db->query('SELECT COUNT(id) FROM '.$db_prefix.'notifications WHERE viewed = 0 AND user_id = '.$id) or error ('Unable to load notifications', __FILE__, __LINE__, $db->error());
$num_not_unseen = $db->result($result);

if ($num_not_unseen == '0') {
$ind_not[] = '<a class="list-group-item disabled" href="me.php?section=notifications&id='.$user['id'].'">No new notifications</a>';
$ind_not[] = '<a class="list-group-item disabled" href="notifications.php?id='.$id.'">No new notifications</a>';
} else {
$result = $db->query('SELECT * FROM '.$db_prefix.'notifications WHERE viewed = 0 AND user_id = '.$user['id'].' ORDER BY time DESC') or error ('Unable to load notifications', __FILE__, __LINE__, $db->error());
$result = $db->query('SELECT * FROM '.$db_prefix.'notifications WHERE viewed = 0 AND user_id = '.$id.' ORDER BY time DESC') or error ('Unable to load notifications', __FILE__, __LINE__, $db->error());
while ($cur_notifi = $db->fetch_assoc($result)) {
$notifitime = format_time($cur_notifi['time'], false, null, $time_format, true, true);
$ind_not[] = '<a class="list-group-item" href="'.$cur_notifi['link'].'"><span class="fa fa-fw '.$cur_notifi['icon'].'"></span> '.$cur_notifi['message'].' <span class="timestamp pull-right">'.$notifitime.'</span></a>';
}
}

$result = $db->query('SELECT COUNT(id) FROM '.$db_prefix.'notifications WHERE viewed = 1 AND user_id = '.$user['id']) or error ('Unable to load notifications', __FILE__, __LINE__, $db->error());
$result = $db->query('SELECT COUNT(id) FROM '.$db_prefix.'notifications WHERE viewed = 1 AND user_id = '.$id) or error ('Unable to load notifications', __FILE__, __LINE__, $db->error());
$num_not_seen = $db->result($result);

if ($num_not_seen == '0') {
$ind_not_seen[] = '<a class="list-group-item disabled" href="me.php?section=notifications&id='.$user['id'].'">No new notifications</a>';
$ind_not_seen[] = '<a class="list-group-item disabled" href="notifications.php?id='.$id.'">No new notifications</a>';
} else {
$result = $db->query('SELECT * FROM '.$db_prefix.'notifications WHERE viewed = 1 AND user_id = '.$user['id'].' ORDER BY time DESC') or error ('Unable to load notifications', __FILE__, __LINE__, $db->error());
$result = $db->query('SELECT * FROM '.$db_prefix.'notifications WHERE viewed = 1 AND user_id = '.$id.' ORDER BY time DESC') or error ('Unable to load notifications', __FILE__, __LINE__, $db->error());
while ($cur_notifi = $db->fetch_assoc($result)) {
$notifitime = format_time($cur_notifi['time'], false, null, $time_format, true, true);
$ind_not_seen[] = '<a class="list-group-item" href="'.$cur_notifi['link'].'"><span class="fa fa-fw '.$cur_notifi['icon'].'"></span> '.$cur_notifi['message'].' <span class="timestamp pull-right">'.$notifitime.'</span></a>';
Expand All @@ -49,15 +49,15 @@
<h2 class="profile-settings-head">Notifications</h2>
<span class="btn-toolbar">
<span class="btn-group">
<a href="me.php?section=notifications&id=2&action=newnoti&type=windows" class="btn btn-default"><span class="fa fa-fw fa-windows"></span></a>
<a href="me.php?section=notifications&id=2&action=newnoti&type=comment" class="btn btn-default"><span class="fa fa-fw fa-comment"></span></a>
<a href="me.php?section=notifications&id=2&action=newnoti&type=check" class="btn btn-default"><span class="fa fa-fw fa-check"></span></a>
<a href="me.php?section=notifications&id=2&action=newnoti&type=version" class="btn btn-default"><span class="fa fa-fw fa-moon-o"></span></a>
<a href="me.php?section=notifications&id=2&action=newnoti&type=cogs" class="btn btn-default"><span class="fa fa-fw fa-cogs"></span></a>
<a href="notifications.php?id=2&action=newnoti&type=windows" class="btn btn-default"><span class="fa fa-fw fa-windows"></span></a>
<a href="notifications.php?id=2&action=newnoti&type=comment" class="btn btn-default"><span class="fa fa-fw fa-comment"></span></a>
<a href="notifications.php?id=2&action=newnoti&type=check" class="btn btn-default"><span class="fa fa-fw fa-check"></span></a>
<a href="notifications.php?id=2&action=newnoti&type=version" class="btn btn-default"><span class="fa fa-fw fa-moon-o"></span></a>
<a href="notifications.php?id=2&action=newnoti&type=cogs" class="btn btn-default"><span class="fa fa-fw fa-cogs"></span></a>
</span>
<span class="btn-group">
<a href="me.php?section=notifications&id=2&action=readnoti" class="btn btn-default">Mark as seen</a>
<a href="me.php?section=notifications&id=2&action=delnoti" class="btn btn-default">Delete seen notifications</a>
<a href="notifications.php?id=2&action=readnoti" class="btn btn-default">Mark as seen</a>
<a href="notifications.php?id=2&action=delnoti" class="btn btn-default">Delete seen notifications</a>
</span>
</span>
<div class="list-group">
Expand Down

0 comments on commit 6605296

Please sign in to comment.