这是代码,错误来自哪里 :) 我希望我能尽快得到答案!!!
function getSubs($id, $type, $start = null) {
if($type == 0) {
if(is_numeric($start)) {
if($start == 0) {
$start = '';
} else {
$start = 'AND `relations`.`id` < \''.$this->db->real_escape_string($start).'\'';
}
$limit = 'LIMIT '.($this->s_per_page + 1);
}
$query = sprintf("SELECT * FROM `relations`, `wp_users` WHERE `relations`.`subscriber` = '%s' AND `relations`.`leader` = `wp_users`.`ID` $start ORDER BY `relations`.`id` DESC $limit", $this->db->real_escape_string($id));
} else {
if(is_numeric($start)) {
if($start == 0) {
$start = '';
} else {
$start = 'AND `relations`.`id` < \''.$this->db->real_escape_string($start).'\'';
}
$limit = 'LIMIT '.($this->s_per_page + 1);
}
$query = sprintf("SELECT * FROM `relations`, `wp_users` WHERE `relations`.`leader` = '%s' AND `relations`.`subscriber` = `wp_users`.`ID` $start ORDER BY `relations`.`id` DESC $limit", $this->db->real_escape_string($id));
}
$result = $this->db->query($query);
while($row = $result->fetch_assoc()) {
$array [] = $row;
}
return array($array, $total = $result->num_rows);
}
function getActions($id, $likes = null, $type = null) {
global $LNG;
if($type == 1) {
$verify = $this->verifyLike($id);
$result = $this->db->query(sprintf("SELECT * FROM `messages`, `wp_users` WHERE `id` = '%s' AND `messages`.`uid` = `wp_users`.`ID`", $this->db->real_escape_string($id)));
if($result->num_rows == 0) {
return $LNG['like_message_not_exist'];
}
if(!$verify) {
$stmt = $this->db->prepare("INSERT INTO `likes` (`post`, `by`) VALUES ('{$this->db->real_escape_string($id)}', '{$this->db->real_escape_string($this->id)}')");
$stmt->execute();
$affected = $stmt->affected_rows;
$stmt->close();
if($affected) {
$this->db->query("UPDATE `messages` SET `likes` = `likes` + 1, `time` = `time` WHERE id = '{$this->db->real_escape_string($id)}'");
$user = $result->fetch_assoc();
$insertNotification = $this->db->query(sprintf("INSERT INTO `notifications` (`from`, `to`, `parent`, `type`, `read`) VALUES ('%s', '%s', '%s', '2', '0')", $this->db->real_escape_string($this->id), $user['uid'], $user['id']));
if($this->email_like) {
if($user['email_like'] && ($this->id !== $user['ID'])) {
sendMail($user['user_email'], sprintf($LNG['ttl_like_email'], $this->username), sprintf($LNG['like_email'], realName($user['user_login'], $user['first_name'], $user['last_name']), $this->url.'/index.php?a=profile&u='.$this->username, $this->username, $this->url.'/index.php?a=post&m='.$id, $this->title, $this->url.'/index.php?a=settings&b=notifications'), $this->email);
}
}
}
} else {
$x = 'already_liked';
}
} elseif($type == 2) {
$verify = $this->verifyLike($id);
$result = $this->db->query(sprintf("SELECT `id` FROM `messages` WHERE `id` = '%s'", $this->db->real_escape_string($id)));
if($result->num_rows == 0) {
return $LNG['like_message_not_exist'];
}
if($verify) {
$stmt = $this->db->prepare("DELETE FROM `likes` WHERE `post` = '{$this->db->real_escape_string($id)}' AND `by` = '{$this->db->real_escape_string($this->id)}'");
$stmt->execute();
$affected = $stmt->affected_rows;
$stmt->close();
if($affected) {
$this->db->query("UPDATE `messages` SET `likes` = `likes` - 1, `time` = `time` WHERE id = '{$this->db->real_escape_string($id)}'");
$this->db->query("DELETE FROM `notifications` WHERE `parent` = '{$this->db->real_escape_string($id)}' AND `type` = '2' AND `from` = '{$this->db->real_escape_string($this->id)}'");
}
} else {
$x = 'already_disliked';
}
}
if($likes == null) {
$query = sprintf("SELECT `likes` FROM `messages` WHERE `id` = '%s'", $this->db->real_escape_string($id));
$result = $this->db->query($query);
$get = $result->fetch_row();
$likes = $get[0];
}
$verify = $this->verifyLike($id);
if($verify) {
$state = $LNG['dislike'];
$y = 2;
} else {
$state = $LNG['like'];
$y = 1;
}
if($this->l_per_post) {
$query = sprintf("SELECT * FROM `likes`,`wp_users` WHERE `post` = '%s' and `likes`.`by` = `wp_users`.`ID` ORDER BY `likes`.`id` DESC LIMIT %s", $this->db->real_escape_string($id), $this->db->real_escape_string($this->l_per_post));
$result = $this->db->query($query);
while($row = $result->fetch_assoc()) {
$array[] = $row;
}
$people = '';
foreach($array as $row) {
$people .= '<a href="'.$this->url.'/index.php?a=profile&u='.$row['user_login'].'"><img src="'.$this->url.'/thumb.php?src='.$row['image'].'&w=25&h=25&t=a" title="'.realName($row['user_login'], $row['first_name'], $row['last_name']).' '.$LNG['liked_this'].'" /></a> ';
}
}
$actions = '<a onclick="doLike('.$id.', '.$y.')" id="doLike'.$id.'">'.$state.'</a> - <a onclick="focus_form('.$id.')">'.$LNG['comment'].'</a> - <a onclick="share('.$id.')">'.$LNG['share'].'</a> <div class="like_btn" id="like_btn'.$id.'"> '.$people.$likes.'</div>';
if(empty($this->id)) {
$actions = '<a href="'.$this->url.'">'.$LNG['login_to_lcs'].'</a> <div class="like_btn"> '.$people.$likes.'</div>';
}
if(isset($x)) {
return $LNG["$x"].' <div class="like_btn"> '.$likes.'</div>';
}
return $actions;
}