public function _index() { // Deny access if not logged in new Protect('ajax'); $post = Input::post(); $token = Token::ajaxCheck($post['token']); $data['success'] = FALSE; $data['errors'] = NULL; if (!empty($post['username'] && $token === TRUE)) { $follow = User::follow($post['username']); if ($follow === TRUE) { $data['success'] = TRUE; } else { $data['errors'][] = $follow; } } else { if (!$token) { $data['errors'][] = 'Security Token Missing'; } else { $data['errors'][] = 'Username Required'; } } if (!empty($data)) { return $data; } else { return FALSE; } }
public function follow() { new Protect(); $post = Input::post(); $token = Token::check($post['token']); if (!empty($post['username'] && $token === TRUE)) { echo User::follow($post['username']); } else { if (!$token) { echo 'Security Token Missing'; } else { Redirect::to('/profile'); } } }
/** * follow or unfollow other users * @author Kydz * @param int $id target id * @return json n/a */ public function follow($id) { $u_id = Input::get('u_id'); $token = Input::get('token'); $type = Input::get('type'); $target = User::find($id); if (!isset($target->u_id)) { return Response::json(['result' => 2001, 'data' => [], 'info' => '您关注的用户不存在']); } if ($id == $u_id) { return Response::json(['result' => 2001, 'data' => [], 'info' => '您不能关注自己']); } try { $user = User::chkUserByToken($token, $u_id); if ($type == 1) { $msg = '关注成功'; User::follow($user, $target); } elseif ($type == 2) { $msg = '取消关注成功'; User::unfollow($user, $target); } $re = ['result' => 2000, 'data' => [], 'info' => $msg]; } catch (Exception $e) { $code = 2001; if ($e->getCode() > 2000) { $code = $e->getCode(); } $re = ['result' => $code, 'data' => [], 'info' => $e->getMessage()]; } return Response::json($re); }
Redirect::redirectTo('404'); } if (isset($_POST['action'])) { $action = $_POST['action']; unset($_POST['action']); } elseif (isset($_GET['action'])) { $action = $_GET['action']; unset($_GET['action']); } else { die("Error! bad request."); } switch ($action) { // follow a user case 'follow': $userID = $_POST['id']; $follow = User::follow($userID); if ($follow === true) { die(json_encode(['status' => true])); } else { die(json_encode(['status' => false, 'err' => $follow])); } break; // unfollow a user // unfollow a user case 'unfollow': $userID = $_POST['id']; $unfollow = User::unfollow($userID); if ($unfollow === true) { die(json_encode(['status' => true])); } else { die(json_encode(['status' => false]));
<?php require_once '../nl-init.php'; require_once '../class/nl-user-class.php'; require_once '../class/nl-auth-class.php'; require_once 'api_headers.php'; $auth = Auth::getInstance(); $userID = $auth->getUserID(); if ($userID <= 0) { return; } if (is_get()) { $user = new User($userID); echo json_encode(array("follows" => $user->follows())); } else { $adminID = _get("adminID", 0); if ($adminID <= 0) { return; } $user = new User($userID); $user->follow($adminID); echo json_encode(array("follows" => $user->follows())); }
$tpl->assign('oNoRecent', true); } if ($user->GetTopPubs(5) !== null) { $tpl->assign('oTopPubs', true); $tpl->assign('iTopPubs', $user->GetTopPubs(5)); } else { $tpl->assign('oNoTopPubs', true); } $tpl->assign('fb_uid', $user->fb_uid); $tpl->assign('name', $user->first_name . ' ' . $user->last_name); $tpl->assign('user_id', $user->user_id); // if user is logged in and it's not his own profile show add as friend button if (SpoonSession::exists('public_uid') && SpoonSession::get('public_uid') != $user->user_id) { $loggedInUser = new User(SpoonSession::get('public_uid'), null, ''); if (!$loggedInUser->isFriend($user->user_id)) { $tpl->assign('oAddFriend', true); } else { $tpl->assign('oDeleteFriend', true); } } if (SpoonFilter::getGetValue('follow', null, '') == 'true') { $loggedInUser->follow($user->user_id); SpoonHTTP::redirect('/users/' . $user->user_id); } if (SpoonFilter::getGetValue('follow', null, '') == 'false') { $loggedInUser->unfollow($user->user_id); SpoonHTTP::redirect('/users/' . $user->user_id); } // show the output $tpl->assign('content', $tpl->getContent('templates/userDetail.tpl')); $tpl->display('templates/layout.tpl');
<?php session_start(); if (!isset($_SESSION['loggeduser_id']) || !$_SESSION['loggeduser_id']) { exit; } require_once "../vars.php"; require_once "../includes/user.class.php"; require_once "../includes/phpmailer/class.phpmailer.php"; if (isset($_POST['user_id']) && isset($_POST['follow'])) { $target_id = $_POST['user_id']; $user = new User(); if ($_POST['follow']) { $target_user = $user->follow($_SESSION['loggeduser_id'], $target_id); $email_settings = $settings->getSetting("email_settings", true); if ($target_user && $email_settings) { // sending email $follower = $user->get($_SESSION['loggeduser_id']); $language = $target_user['language']; require_once "../language/" . $language . "/general.php"; require_once "../language/" . $language . "/user.php"; $mailsubject = $lang['user_follow_mail_subject']; $mailcontent = $lang['user_follow_mail_content']; $mailcontent = str_replace("#sitename#", $sitename, $mailcontent); $mailcontent = str_replace("#baseurl#", $baseurl, $mailcontent); $mailcontent = str_replace("#follower_username#", $follower['username'], $mailcontent); $mailcontent = str_replace("#target_username#", $target_user['username'], $mailcontent); $mailcontent = str_replace("#follower_profile_url#", $baseurl . "/user/" . $follower['username'], $mailcontent); $mailcontent = str_replace("#mailcontent#", $mailcontent, file_get_contents("../language/" . $language . "/email_template.html")); $mailcontent = str_replace("#sitename#", $sitename); $mailcontent = str_replace("#baseurl#", $baseurl);