-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcomment_ajax.php
More file actions
123 lines (107 loc) · 5.69 KB
/
Copy pathcomment_ajax.php
File metadata and controls
123 lines (107 loc) · 5.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
/*
* You may not change or alter any portion of this comment or credits
* of supporting developers from this source code or any supporting source code
* which is considered copyrighted (c) material of the original comment or credit authors.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/**
* SmallWorld
*
* @package \XoopsModules\Smallworld
* @license GNU GPL (https://www.gnu.org/licenses/gpl-2.0.html/)
* @copyright The XOOPS Project (https://xoops.org)
* @copyright 2011 Culex
* @author Michael Albertsen (http://culex.dk) <culex@culex.dk>
* @link https://github.com/XoopsModules25x/smallworld
* @since 1.0
*/
use Xmf\Request;
use XoopsModules\Smallworld;
use XoopsModules\Smallworld\Constants;
require_once __DIR__ . '/header.php';
/** @var \XoopsModules\Smallworld\Helper $helper */
require_once $helper->path('include/functions.php');
require_once XOOPS_ROOT_PATH . '/class/template.php';
$GLOBALS['xoopsLogger']->activated = false;
//error_reporting(E_ALL);
$page = 'index';
/** @var \XoopsModules\Smallworld\SwUserHandler $swUserHandler */
$swUserHandler = $helper->getHandler('SwUser');
$check = new Smallworld\User();
$id = $GLOBALS['xoopsUser'] ? $GLOBALS['xoopsUser']->getVar('uid') : Constants::DEFAULT_UID;
//$profile = $GLOBALS['xoopsUserl'] ? $check->checkIfProfile($id) : Constants::PROFILE_NONE;
$profile = $swUserHandler->checkIfProfile($id);
if ($profile >= Constants::PROFILE_HAS_BOTH) {
$Xuser = new \XoopsUser($id);
$username = $Xuser->getVar('uname');
$wall = new Smallworld\WallUpdates();
$tpl = new \XoopsTpl();
$mail = new Smallworld\Mail();
$swDB = new Smallworld\SwDatabase();
if (isset($_POST['comment'])) {
$tpl->assign('isadminuser', $helper->isUserAdmin() ? 'YES' : 'NO');
$followers = smallworld_array_flatten($wall->getFollowers($id), 0);
$myavatar = $swUserHandler->gravatar($id);
$myavatarlink = $swUserHandler->getAvatarLink($id, $myavatar);
// Get posted items
$comment = Request::getString('comment', '', 'POST');
$msg_id = Request::getInt('msg_id', Constants::DEFAULT_MESSAGEID, 'POST');
$data = $wall->insertComment($id, $msg_id, $comment);
if ($data) {
// Is comments' user a friend ?
$frC = $check->friendcheck($id, $data['uid_fk']);
$USC = ['posts' => 0, 'comments' => 0];
if ($helper->isUserAdmin() || $data['uid_fk'] == $id) {
$USC['posts'] = 1;
$USC['comments'] = 1;
$frC[0] = Constants::PROFILE_HAS_BOTH;
} else {
$USC = json_decode($swDB->getSettings($data['uid_fk']), true);
}
$wc['msg_id_fk'] = $data['msg_id_fk'];
$wc['com_id'] = $data['com_id'];
$wc['comment'] = (1 == $USC['comments'] || Constants::PROFILE_HAS_BOTH == $frC[0]) ? smallworld_tolink(htmlspecialchars_decode($data['comment']), $data['uid_fk']) : _SMALLWORLD_MESSAGE_PRIVSETCOMMENTS;
$wc['comment'] = smallworld_cleanup($wc['comment']);
$wc['time'] = smallworld_time_stamp($data['created']);
$wc['username'] = $data['username'];
$wc['uid'] = $data['uid_fk'];
$wc['myavatar'] = $myavatar;
$wc['myavatar_link'] = $myavatarlink;
$wc['cface'] = $swUserHandler->gravatar($data['uid_fk']);
$wc['avatar_link'] = $swUserHandler->getAvatarLink($data['uid_fk'], $wc['cface']);
$wc['avatar_size'] = smallworld_getImageSize(80, 100, $wc['myavatar_link']);
$wc['avatar_highwide'] = smallworld_imageResize($wc['avatar_size'][0], $wc['avatar_size'][1], 35);
$wc['compl_msg_lnk'] = "<a href='" . $helper->url('permalink.php?ownerid=' . smallworld_getOwnerFromComment($data['msg_id_fk']));
$wc['compl_msg_lnk'] .= '&updid=' . $data['msg_id_fk'] . '#' . $data['com_id'] . "'>" . _SMALLWORLD_COMP_MSG_LNK_DESC . '</a>';
$wc['vote_up'] = $wall->countVotesCom('com', 'up', $data['msg_id_fk'], $data['com_id']);
$wc['vote_down'] = $wall->countVotesCom('com', 'down', $data['msg_id_fk'], $data['com_id']);
//Send mail if tagged
$permalink = $helper->url('permalink.php?ownerid=' . $data['uid_fk'] . '&updid=' . $data['msg_id_fk']);
smallworld_getTagUsers($wc['comment'], $wc['uid'], $permalink);
$tpl->append('comments', $wc);
$tpl->assign([
'myusername' => $username,
'pagename' => $page,
'myavatar' => $myavatar,
'myavatarlink' => $myavatarlink
]);
$tpl->display($helper->path('templates/getlastcom.tpl'));
// send mail to user owning update + participans in the thread that a comment has been posted
$parts = $mail->getPartsFromComment($data['msg_id_fk']);
foreach ($parts as $v) {
$owner = smallworld_getOwnerFromComment($data['msg_id_fk']);
// Get owner of posts settings in order to send mail or not!
$owner_privset = json_decode($swDB->getSettings($v), true);
if (0 !== $helper->getConfig('smallworldusemailnotis')) {
if (1 == $owner_privset['notify']) {
$mail->sendMails($data['uid_fk'], $v, 'commentToWM', null, $wc);
}
}
}
}
}
}