php Comments Class by Bagir AKA Stajor -------------------- ----------

  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
<?php
/*
=====================================================
Comments Class - by Bagir AKA Stajor
-----------------------------------------------------
http://www.porta.co.il/
-----------------------------------------------------
Copyright (c) 2007
=====================================================
Данный код защищен авторскими правами
=====================================================
Файл: friends.class.php
-----------------------------------------------------
Назначение: управление друзьями на сайте
=====================================================
*/
final class Friends extends db
{
private $chpu;
private $self_path;
private $member_id;
private $is_logged;
private $is_friend = false;
private $user_name;
public $err = false;
private $lng;
function __construct($sys_conf, $member_id, $is_logged, $lng){
$this->user_name = urldecode($_REQUEST['user']);
if ($this->user_name == $member_id['name'] || !$is_logged) $this->is_friend = true;
$this->member_id = $member_id;
$this->is_logged = $is_logged;
$this->chpu = $sys_conf['allow_alt_url'];
if ($this->chpu == 'yes') $this->self_path = $sys_conf['http_home_url']."friends/";
else $this->self_path = $sys_conf['http_home_url']."?do=friends";
$this->engine_path = $sys_conf['http_home_url'];
$this->lng = $lng;
}
public function GetList() {
$fr_link = array();
$name = $this->safesql($this->user_name);
$result = $this->query("SELECT u.name, f.friend_id FROM ".PREFIX."_users_friends f, ".PREFIX."_users u
WHERE f.user_id = (SELECT user_id FROM ".PREFIX."_users WHERE name = '$name')
AND f.approve = 1 AND u.user_id = f.friend_id ORDER BY u.name");
while ($row = $this->get_row($result)){
if (!$this->is_friend && $row['name'] == $this->member_id['name']) $this->is_friend = true;
if ($this->user_name != $this->member_id['name'] || !$this->is_logged) $del_link = "";
else {
$fr_key = base64_encode($row['friend_id'].'#no#'.$this->member_id['user_id']);
if ($this->chpu == 'yes') $del_link = " <a href='{$this->self_path}delete/$fr_key' style='color:red'>(X)</a>";
else $del_link = " <a href='{$this->self_path}&op=delete&key=$fr_key' style='color:red'>(X)</a>";
}
$l_name = urlencode($row['name']);
if ($this->chpu == 'yes') $fr_link[] = "<a href='{$this->engine_path}user/$l_name/'>$row[name]</a>".$del_link;
else $fr_link[] = "<a href='{$this->engine_path}?subaction=userinfo&user=$l_name'>$row[name]</a>".$del_link;
}
$this->free($result);
return implode(", ", $fr_link);
}
public function Profile($tpl){
$tpl->set("{friends}", $this->GetList());
if (!$this->is_friend){
$key = base64_encode($this->member_id['user_id'].'#'.$this->user_name);
if ($this->chpu == "yes") $inv_link = $this->self_path."invite/$key";
else $inv_link = $this->self_path."&op=invite&key=".$key;
$tpl->set('[invfriend]', "<a href='$inv_link'>");
$tpl->set('[/invfriend]', '</a>');
}
else $tpl->set_block("'\\[invfriend\\](.*?)\\[/invfriend\\]'si","");
}
public function Invite($config){
$ex = explode('#', base64_decode($_REQUEST['key']));
$friend_id = intval($ex[0]);
$to_user = $this->safesql($ex[1]);
$to_userid = $this->super_query("SELECT user_id, email FROM ".PREFIX."_users WHERE name = '$to_user' LIMIT 1");
if ($this->is_friend || $this->member_id['name'] == $to_user) {
$this->err = $this->lng['no_access'];
return;
}
$row = $this->super_query("SELECT approve FROM ".PREFIX."_users_friends WHERE friend_id = '$friend_id'
AND user_id = '{$to_userid['user_id']}' LIMIT 1");
if ($row) {
if ($row['approve'] == 1) $this->err = $this->lng['is_friend'];
else $this->err = $this->lng['friend_send'];
return;
}
$subject = $this->lng['friend_subj'];
$aprove = base64_encode($this->member_id['user_id']."#yes#".$to_userid['user_id']);
$notaprove = base64_encode($this->member_id['user_id']."#no#".$to_userid['user_id']);
$result = $this->query("SELECT template, name FROM ".PREFIX."_email WHERE name IN ('frnd_mail', 'frnd_pm') LIMIT 2");
$lname = urlencode($this->member_id['name']);
if ($this->chpu == "yes") {
$from_link = "<a href='{$this->engine_path}user/$lname/'>{$this->member_id['name']}</a>";
$aprove_lnk = $this->self_path."approve/$aprove";
$noaprove_lnk = $this->self_path."approve/$notaprove";
}
else {
$aprove_lnk = $this->self_path."&op=approve&key=$aprove";
$noaprove_lnk = $this->self_path."&op=approve&key=$notaprove";
$from_link = "<a href='{$this->engine_path}?subaction=userinfo&user=$lname'>{$this->member_id['name']}</a>";
}
while ($tpl = $this->get_row($result)){
$mail_find = array('{%username_to%}','{%username%}','{%site%}','{%aprove%}','{%notaprove%}');
$mail_replace = array($to_user, $from_link, $this->engine_path, $aprove_lnk, $noaprove_lnk);
$tpl['template'] = stripcslashes($tpl['template']);
$tpl['template'] = str_replace($mail_find, $mail_replace, $tpl['template']);
if($tpl['name'] == 'frnd_mail'){
$tpl['template'] = str_replace($mail_find, $mail_replace, str_replace("\n","<br />",$tpl['template']));
$mail = new dle_mail ($config);
$mail->html_mail = true;
$mail->send ($to_userid['email'], $subject, $tpl['template']);
}
elseif($tpl['name'] == 'frnd_pm') {
$tpl['template'] = $this->safesql($tpl['template']);
$time = time();
$this->query("INSERT INTO ".PREFIX."_pm (subj, text, user, user_from, date, pm_read, folder)
VALUES ('$subject', '$tpl[template]',{$to_userid['user_id']}, '{$this->member_id['name']}',
'$time', 'no', 'inbox')");
$this->query("UPDATE ".PREFIX."_users SET pm_all = pm_all + 1, pm_unread = pm_unread + 1
WHERE user_id = {$to_userid['user_id']}");
}
}
$this->query("INSERT INTO ".PREFIX."_users_friends VALUES ('{$to_userid['user_id']}', '$friend_id', NOW(), 0, 0)");
$this->query("INSERT INTO ".PREFIX."_users_friends VALUES ('$friend_id', '{$to_userid['user_id']}', NOW(), 0, 0)");
$this->free();
$this->err = $this->lng['friend_send'];
}
public function Aprove(){
$ex = explode('#', base64_decode($_REQUEST['key']));
$to_userid = intval($ex[2]);
$from_userid = intval($ex[0]);
$status = $ex[1];
$row = $this->super_query("SELECT approve FROM ".PREFIX."_users_friends WHERE user_id = '$to_userid'
AND friend_id = '$from_userid' LIMIT 1");
if (($this->is_friend || $row['approve'] == 1) && $status != 'no'){
$this->err = $this->lng['err_act'];
return ;
}
if ($status == 'no' && $this->member_id['user_id'] == $to_userid){
$this->query("DELETE FROM ".PREFIX."_users_friends WHERE user_id = '$to_userid' AND friend_id = '$from_userid'");
$this->query("DELETE FROM ".PREFIX."_users_friends WHERE user_id = '$from_userid' AND friend_id = '$to_userid'");
}
else {
$this->query("UPDATE ".PREFIX."_users_friends SET approve = 1
WHERE user_id = '$to_userid' AND friend_id = '$from_userid'");
$this->query("UPDATE ".PREFIX."_users_friends SET approve = 1
WHERE user_id = '$from_userid' AND friend_id = '$to_userid'");
}
$this->free();
if (($to_userid / 100) < 1) $fldr = 1;
else $fldr = floor($to_userid / 100) * 100;
@unlink(ENGINE_DIR."/uploads/userpage/$fldr/$to_userid/cache/pp_friends.tmp");
if (($from_userid / 100) < 1) $fldr = 1;
else $fldr = floor($from_userid / 100) * 100;
@unlink(ENGINE_DIR."/uploads/userpage/$fldr/$from_userid/cache/pp_friends.tmp");
$this->err = $this->lng['friend_act'];
}
}
?>