forked from boonex/dolphin.pro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgreet.php
220 lines (180 loc) · 7.14 KB
/
greet.php
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<?php
/**
* Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
* CC-BY License - http://creativecommons.org/licenses/by/3.0/
*/
require_once( 'inc/header.inc.php' );
require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );
require_once( BX_DIRECTORY_PATH_INC . 'profiles.inc.php' );
require_once( BX_DIRECTORY_PATH_CLASSES . 'BxDolEmailTemplates.php' );
// --------------- page variables
$_page['name_index'] = bx_get('fullpage') == 1 ? 7 : 44;
$logged['member'] = member_auth(0, false);
// --------------- page components
//define ajax mode
$bAjxMod = isset($_SERVER['HTTP_X_REQUESTED_WITH'])
&& $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ? true : false;
if ($bAjxMod) {
header('Content-Type: text/html; charset=utf-8');
echo MsgBox(getMainCode());
exit;
}
$_ni = $_page['name_index'];
$_page_cont[$_ni]['page_main_code'] = DesignBoxContent(_t('_Send virtual kiss'), getMainCode(), $oTemplConfig->PageVkiss_db_num);
$_page_cont[$_ni]['body_onload'] = '';
// --------------- [END] page components
PageCode();
// --------------- page components functions
/**
* page code function
*/
function getMainCode()
{
global $_page;
$member['ID'] = getLoggedId();
$member['Password'] = getLoggedPassword;
if( false != bx_get('ConfCode') && false != bx_get('sendto') ) {
$recipientID = (int) bx_get('sendto');
} else {
//check post value
$recipientID = isset($_POST['sendto']) ? $_POST['sendto'] : -1;
}
$recipient = getProfileInfo( $recipientID );
$isCheckVisitorGreeting = true;
if(!$recipient || $recipientID == $member['ID']) {
return MsgBox( _t('_Error Occured') );
}
ob_start();
?>
<table width="100%" cellpadding="4" cellspacing="4" border="0">
<tr>
<td align="center" class="text2">__content__<br/></td>
</tr>
</table>
<?php
$sResTmpl = ob_get_clean();
$ret = '';
$sKissKey = '_Send virtual kiss';
$sJQueryJS = genAjaxyPopupJS($recipientID);
$_page['header'] = _t($sKissKey);
if ( $_GET['ConfCode'] && $_GET['from'] &&
( strcmp( $_GET['ConfCode'], base64_encode( base64_encode( crypt( $_GET['from'], CRYPT_EXT_DES ? "vkiss_sec" : "vk") ) ) ) == 0 ) )
{
$member['ID'] = (int)$_GET['from'];
$isCheckVisitorGreeting = false;
}
//
// Check if member can send messages
$check_res = checkAction( $member['ID'], ACTION_ID_SEND_VKISS );
if ( $check_res[CHECK_ACTION_RESULT] != CHECK_ACTION_RESULT_ALLOWED) {
$_page['header_text'] = _t($sKissKey . '3');
$ret = $GLOBALS['oSysTemplate']->parseHtmlByContent($sResTmpl, array('content' => $check_res[CHECK_ACTION_MESSAGE]));
return $ret . $sJQueryJS;
}
$action_result = "";
// Perform sending
$send_result = MemberSendVKiss( $member, $recipient, $isCheckVisitorGreeting );
switch ( $send_result ) {
case 1:
$action_result .= _t_err( "_VKISS_BAD" );
break;
case 7:
$action_result .= _t_err( "_VKISS_BAD_COUSE_B" );
break;
case 10:
$action_result .= _t_err( "_VKISS_BAD_COUSE_C" );
break;
case 13:
$action_result .= _t_err( "_VKISS_BAD_COUSE_A3" );
break;
case 23:
$action_result .= _t_err( "_VKISS_BAD_COUSE_X" );
break;
case 24:
$action_result .= _t_err( "_VKISS_BAD_COUSE_Y" );
break;
default:
$action_result .= _t("_VKISS_OK" );
break;
}
if ($send_result == 0)
$_page['header_text'] = _t($sKissKey .'2');
else
$_page['header_text'] = _t($sKissKey .'3');
$ret = $GLOBALS['oSysTemplate']->parseHtmlByContent($sResTmpl, array('content' => $action_result));
return $ret . $sJQueryJS;
}
/**
* Send virtual kiss
*/
function MemberSendVKiss( $member, $recipient, $isCheckVisitorGreeting = true )
{
global $logged;
// Check if recipient is active
if( 'Active' != $recipient['Status'] ) {
return 7;
}
// block members
if( $recipient['ID'] && $member['ID'] && isBlocked( (int)$recipient['ID'], (int)$member['ID']) ) {
return 24;
}
// Get sender info
$sender = getProfileInfo( $member['ID'] );
// Send email notification
$rEmailTemplate = new BxDolEmailTemplates();
if ( $logged['member'] || !$isCheckVisitorGreeting) {
$aTemplate = $rEmailTemplate -> getTemplate( 't_VKiss', $_COOKIE['memberID'] ) ;
} else {
$aTemplate = $rEmailTemplate -> getTemplate( 't_VKiss_visitor' ) ;
}
$sConfCode = urlencode( base64_encode( base64_encode( crypt( $recipient['ID'], CRYPT_EXT_DES ? "vkiss_sec" : "vk" ) ) ) );
// parse the email template ;
$sProfileLink = $sender
? '<a href="' . getProfileLink($member['ID']) . '">' . getNickName($sender['ID']) . '</a>'
: '<b>' . _t("_Visitor") . '</b>';
$sKissLink = $sender
? '<a href="' . BX_DOL_URL_ROOT . 'greet.php?fullpage=1&sendto=' . $member['ID'] . '&from=' . $recipient['ID'] . '&ConfCode=' . $sConfCode . '">' . BX_DOL_URL_ROOT . 'greet.php?sendto=' . $member['ID'] . '&from=' . $recipient['ID'] . '&ConfCode=' . $sConfCode . '</a>'
: '<a href="' . BX_DOL_URL_ROOT . 'communicator.php">' . BX_DOL_URL_ROOT . 'communicator.php</a>';
$aRepl = array(
'<ConfCode>' => $sConfCode,
'<ProfileReference>' => $sProfileLink,
'<VKissLink>' => $sKissLink,
'<RealName>' => getNickName($recipient['ID']),
'<SiteName>' => BX_DOL_URL_ROOT,
);
$aTemplate['Body'] = str_replace(array_keys($aRepl), array_values($aRepl), $aTemplate['Body']);
$mail_ret = sendMail( $recipient['Email'], $aTemplate['Subject'], $aTemplate['Body'], $recipient['ID'] );
// Send message into the member's site personal mailbox;
$aTemplate['Subject'] = process_db_input($aTemplate['Subject'], BX_TAGS_NO_ACTION);
$aTemplate['Body'] = process_db_input($aTemplate['Body'], BX_TAGS_NO_ACTION);
$sender['ID'] = ( !$sender['ID'] ) ? 0 : $sender['ID'] ;
$sQuery =
"
INSERT INTO
`sys_messages`
SET
`Date` = NOW(),
`Sender` = '{$sender['ID']}',
`Recipient` = '{$recipient['ID']}',
`Subject` = '{$aTemplate['Subject']}',
`Text` = '{$aTemplate['Body']}',
`New` = '1',
`Type` = 'greeting'
";
db_res($sQuery);
if ( !$mail_ret ) {
return 10;
}
// Insert kiss into database
$kiss_arr = db_arr( "SELECT `ID` FROM `sys_greetings` WHERE `ID` = {$member['ID']} AND `Profile` = {$recipient['ID']} LIMIT 1", 0 );
if ( !$kiss_arr )
$result = db_res( "INSERT INTO `sys_greetings` ( `ID`, `Profile`, `Number`, `When`, `New` ) VALUES ( {$member['ID']}, {$recipient['ID']}, 1, NOW(), '1' )", 0 );
else
$result = db_res( "UPDATE `sys_greetings` SET `Number` = `Number` + 1, `New` = '1' WHERE `ID` = {$member['ID']} AND `Profile` = {$recipient['ID']}", 0 );
// If success then perform actions
if ( $result )
checkAction( $member['ID'], ACTION_ID_SEND_VKISS, true );
else
return 1;
return 0;
}