function resourceGet($api, $tools, $param) { $param["fbId"] = $tools->sql_injection_anti($_SESSION["fbId"]); $param["list"] = empty($_POST["list"]) ? 0 : $tools->sql_injection_anti($_POST["list"]); include_once "../../library/Table/User.class.php"; $user = new User(); $userData = $user->getByFbId($param['fbId']); if (empty($userData)) { $api->setError("查無玩家資料!"); unset($userData, $user, $param); return; } else { include_once "../../library/Table/Friend.class.php"; $friend = new Friend(); $invite = $friend->getGameNum($param['fbId']); $list = $friend->listFriend($param['fbId']); if ($param["list"]) { $api->setOutput("取得好友人數", array("list" => $list)); } else { $api->setOutput("取得好友人數", array("num" => count($invite))); } unset($list, $invite); } unset($userData, $friend, $user, $param); reuturn; }
public function run() { $uid = Yii::app()->user->id; $ret = array(); if (!$uid) { $ret = array('state' => 'error', 'message' => Yii::t('common', 'You Need Login')); } else { $act = Yii::app()->request->getParam('act'); $friendid = Yii::app()->request->getParam('id'); $friend = User::model()->findByPk($friendid); if (!$friend) { $ret = array('state' => 'error', 'message' => Yii::t('common', 'Add Friend Failed')); } else { $friend_mod = new Friend(); if ($act == 'friend') { $exist_friend = $friend_mod->find('user_id = :uid AND friend_user_id = :friendid', array(':uid' => $uid, ':friendid' => $friendid)); if ($exist_friend) { $ret = array('state' => 'error', 'message' => Yii::t('common', 'You are Friend')); } else { //添加好友 $friend_mod->user_id = $uid; $friend_mod->friend_user_id = $friendid; if ($friend_mod->save()) { $ret = array('state' => 'success', 'message' => Yii::t('common', 'Add Friend Success')); } else { $ret = array('state' => 'error', 'message' => Yii::t('common', 'Add Friend Failed')); } } } else { $ret = array('state' => 'error', 'message' => Yii::t('common', 'Operation Failed')); } } } exit(CJSON::encode($ret)); }
function index($id = null) { //name of folder and file $u = new Login(); $requestController = new Friend_Request(); // only me get access right now $friendCon = new Friend(); $this->view->styles = array(); array_push($this->view->styles, URL . "/Public/bootstrap/css/styles.css"); array_push($this->view->styles, URL . "/Public/bootstrap/css/post.css"); if ($id == null || $id == Session::get('id')) { $this->view->me = true; $this->view->id = Session::get('id'); $this->view->access = true; $this->view->user = $u::getUser(Session::get('id')); $this->view->posts = $this->getPosts(Session::get('id')); } else { $this->view->me = false; if ($friendCon->isFriend(Session::get('id'), $id)) { $this->view->access = true; $this->view->posts = $this->getPosts($id); } else { $this->view->access = false; $this->view->requested = $requestController->isRequested($id); $this->view->posts = $this->getPosts($id, "public"); } $this->view->id = $id; $this->view->user = $u::getUser($id); } $this->view->render('post/index'); }
/** * check if values $_REQUEST[''] exist - then get friend by id (existing friend) * if values not exist then create a new friend (new friend) * @return array */ protected function run() { if (array_key_exists('id', $_REQUEST) and $_REQUEST['id'] > 0) { $friend = Friends::getFriendByID($_REQUEST['id']); } else { $friend = new Friend(); } /** * if $_POST_[""] is not empty then set the values into the template * else set error massage if one of the $_POST[""] is empty */ if (!empty($_POST["name"]) and !empty($_POST["adress"]) and !empty($_POST["email"])) { $friend->setName($_POST["name"]); $friend->setAdress($_POST["adress"]); $friend->setEmail($_POST["email"]); /** * records can be saved after editing or creating * exit the program after a successful storage * error massage when email address exists because email address is unique */ if ($friend->save()) { header('location:index.php?module=listoffriends'); exit; } else { $var = array('fehler' => "Die Person existiert bereits in der Datenbank"); } } elseif (!empty($_POST["name"]) or !empty($_POST["adress"]) or !empty($_POST["email"])) { $var = array('fehler' => "Es sind nicht alle Datenfelder ausgefüllt"); } $var['friend'] = $friend; return $var; }
public function friendDeleteAction() { $friendUserID = Input::get('friend_user_id'); $userID = Auth::user()->id; $friendModel = new Friend(); $friendModel->deleteFriend($userID, $friendUserID); return Redirect::to('friends')->with('message', 'Friend Removed'); }
public function getFriends($userID) { $friendModel = new Friend(); $friends = $friendModel->getFriends($userID); $output = array(); if (count($friends) > 0) { foreach ($friends as $friend) { $output[$friend->user_id] = $friend->first_name . ' ' . $friend->last_name; } } return $output; }
public function executeAdd() { $touserid = $this->getRequestParameter('id'); $touser = UserPeer::retrieveByPK($touserid); $fromuserid = $this->getUser()->getAttribute('userid'); $friend = new Friend(); $friend->setUserId($touserid); $friend->save(); $userfriend = new Userfriend(); $userfriend->setUserId($fromuserid); $userfriend->setFriendId($friend->getId()); $userfriend->save(); $this->setFlash('notice', '<font style="background-color: yellow"><b>' . $touser->getFullname() . '</b>has been marked as friend.</font>'); $this->redirect('search/result?page=' . $this->getUser()->getAttribute('srpage')); }
public function executeAccept(sfWebRequest $request) { $friendRequest = new FriendRequest(); $friendRequest->uid_to = $this->getUser()->getAttribute('id'); $friendRequest->uid_from = $request->getParameter('uid'); $profile = Doctrine_Core::getTable('Profile')->findOneByUid($friendRequest->uid_from); $x = Doctrine_Core::getTable('FriendRequest')->createQuery('a')->where("uid_from = {$friendRequest->uid_from} AND uid_to = {$friendRequest->uid_to}")->execute(); $x->delete(); $friend = new Friend(); $friend->uid1 = $this->getUser()->getAttribute('id'); $friend->uid2 = $request->getParameter('uid'); $friend->save(); $this->getUser()->setFlash('info', "You successfully accepted {$profile->first_name}'s friend request."); $this->redirect($this->getUser()->getAttribute('redirect_back')); }
public function handleRequest() { $arr = array('idusers' => $_SESSION['UID']); $content = Place::findMyPlaces($arr); $friend = Friend::find($arr); render('home', array('title' => "" . $_SESSION['UNAME'] . ' Welcome to the Places', 'content' => $content, 'friend' => $friend)); }
public function run($id) { $controller = $this->getController(); $this->_setting = $controller->_setting; $this->_stylePath = $controller->_stylePath; $this->_static_public = $controller->_static_public; $myself = false; //加载css,js Yii::app()->clientScript->registerCssFile($this->_stylePath . "/css/user.css"); Yii::app()->clientScript->registerScriptFile($this->_static_public . "/js/jquery/jquery.js"); //用户信息 $user = User::model()->findByPk($id); //当前登录用户 $uid = Yii::app()->user->id; if (!$user) { throw new CHttpException(404, Yii::t('common', 'The requested page does not exist.')); exit; } else { $data = array(); $group = UserGroup::model()->findByPk($user->groupid); $data['uid'] = $user->uid; $data['username'] = $user->username; $data['email'] = $user->email; $data['register_ip'] = $user->register_ip; $data['last_login_ip'] = $user->last_login_ip; $data['group_name'] = $group->group_name; $data['mobile'] = $user->mobile; $data['web'] = $user->web; $data['qq'] = $user->qq; $data['addtime'] = $user->addtime; $data['avatar'] = $user->avatar; $data['sign'] = $user->sign; //SEO $controller->_seoTitle = $user->username . ' - ' . Yii::t('common', 'User Space') . ' - ' . $this->_setting['site_name']; //判断是否是自己 if ($uid == $user->uid) { $myself = true; } //判断是否是好友 $friend_mod = new Friend(); $friend = $friend_mod->find('uid1=:uid AND uid2=:friendid', array(':uid' => $uid, ':friendid' => $user->uid)); if (!$friend) { $friend = $friend_mod->find('uid1=:uid AND uid2=:friendid', array(':uid' => $user->uid, ':friendid' => $uid)); } } $controller->render('user_space', array('user' => $data, 'myself' => $myself, 'friend' => $friend)); }
public function run() { $friendsFrom = Friend::model()->with('userTo')->findAllByAttributes(array('idUserFrom' => $this->idUser, 'accepted' => 1)); $friendsTo = Friend::model()->with('userFrom')->findAllByAttributes(array('idUserTo' => $this->idUser, 'accepted' => 1)); $datas = array_merge($friendsFrom, $friendsTo); shuffle($datas); $this->render('friendsOverview', array('datas' => $datas)); }
function accept($friend_id) { $id = Session::get('id'); $this->model->deleteRequest($id, $friend_id); Friend::addFriend($friend_id, $id); header('Location:' . URL . '/friend/getFriends'); die; }
public function deleteFriend($userID, $friendUserID) { DB::transaction(function () use($userID, $friendUserID) { $friendModel = Friend::where('user_id', '=', $userID)->where('friend_user_id', '=', $friendUserID)->delete(); $inverseFriendModel = Friend::where('user_id', '=', $friendUserID)->where('friend_user_id', '=', $userID)->delete(); }); return true; }
function friends_activity(&$vars) { global $db, $main_smarty; $author_id = $vars['author_id']; $linkid = $vars['link_id']; //for friends voting activity include_once mnminclude . 'friend.php'; $friend = new Friend(); $sql = 'SELECT ' . table_votes . '.*, ' . table_users . '.user_id FROM ' . table_votes . ' INNER JOIN ' . table_users . ' ON ' . table_votes . '.vote_user_id = ' . table_users . '.user_id WHERE (((' . table_votes . '.vote_value)>0) AND ((' . table_votes . '.vote_link_id)=' . $linkid . ') AND (' . table_votes . '.vote_type= "links"));'; $voters = $db->get_results($sql); $voters = object_2_array($voters); foreach ($voters as $key => $val) { $voteduserid = $val['user_id']; if ($voteduserid == $friend->get_friend_status($author_id)) { $vars['value'] = true; } $main_smarty->assign('friendvoted', $friendvoted); } }
public function renderContent() { $friends_label = "<span class='glyphicon-parents'></span> " . t('Друзья') . ' (' . Friend::userFriendsCount(Yii::app()->user->id) . ')'; if ($new_friends_count = Friend::userFriendsCount(Yii::app()->user->id, 0, 'in')) { $friends_label .= CHtml::link("<span class='badge badge-success'>+" . $new_friends_count . "</span>", array('/social/friend/index', 'user_id' => Yii::app()->user->id, 'type' => 'in'), array('title' => t('новые заявки в друзья'))); } $messages_label = "<span class='glyphicon-message-plus'></span> " . t('Сообщения') . ' (' . Yii::app()->user->messages_count . ')'; $items = array(array('label' => $messages_label, 'url' => $this->createUrl('/messages/message/index')), array('label' => $friends_label, 'url' => $this->createUrl('/social/friend/index', array('user_id' => Yii::app()->user->id))), array('label' => "<span class='glyphicon-star'></span> " . t('Избранное') . ' (' . Yii::app()->user->favorites_count . ')', 'url' => $this->createUrl('')), array('label' => "<span class='glyphicon-file'></span> " . t('Страницы') . ' (' . Yii::app()->user->pages_count . ')', 'url' => $this->createUrl('')), array('label' => "<span class='glyphicon-comments'></span> " . t('Комментарии') . ' (' . Yii::app()->user->comments_count . ')', 'url' => $this->createUrl('/comments/comment/userComments', array('user_id' => Yii::app()->user->id)))); $title = Yii::app()->request->getParam('id') == Yii::app()->user->id ? t('Ваша инофрмация') : t('Информация о пользователе'); $this->render('UserPageSidebar', array('items' => $items, 'title' => $title)); }
public static function followPrestiges($userid) { try { $prestiges = CacheManager::getPrestigeCache(1000, 0); if (isset($prestiges) && is_array($prestiges)) { foreach ($prestiges as $prestige) { $friend = new Friend(); $friend->author_id = $userid; $friend->friend_id = $prestige['id']; $friend->friend_photo_url = $prestige['user_pic_url']; $friend->friend_username = $prestige['nickname']; $friend->create_date = new CDbExpression('NOW()'); $friend->status = Constants::OBJECT_APPROVAL; $friend->save(); User::model()->updateFanCount($prestige['id'], 1); } User::model()->updateFollowUserCount($userid, count($prestiges)); } } catch (Exception $e) { } }
public function login($username, $password) { if ($user = User::authenticate($username, $password)) { // user just logged in, update login time. $user->lastLogin(time()); $_SESSION['username'] = $user->username; $_SESSION['user_id'] = intval($user->user_id); $online = Friend::of($user->user_id); return array('r' => 'logged in', 's' => session_id(), 'f' => $online); } else { return array('r' => 'error', 'e' => 'invalid user'); } }
public function __construct() { if (!pageArray(2)) { return false; } gateKeeper(); $user1 = getLoggedInUser(); $guid = pageArray(2); $user2 = getEntity($guid); if (!FriendsPlugin::friends($user1->guid, $user2->guid)) { // First check if the other user has already initiated a friend request $request = getEntity(array("type" => "Friend", "metadata_name_value_pairs" => array(array("name" => "guid_one", "value" => $guid), array("name" => "guid_two", "value" => $user1->guid), array("name" => "status", "value" => "new")))); if ($request) { FriendsPlugin::addFriend($user1->guid, $guid); forward(); } // Make sure there isn't already a friend request in the system $test = getEntities(array("type" => "Friend", "metadata_name_value_pairs" => array(array("name" => "guid_one", "value" => $user1->guid), array("name" => "guid_two", "value" => $guid)))); if (!$test) { $friend_request = new Friend(); $friend_request->guid_one = $user1->guid; $friend_request->guid_two = $guid; $friend_request->status = "requested"; $friend_request->requested_by = getLoggedInUserGuid(); $friend_request->save(); $friend_request = new Friend(); $friend_request->guid_one = $guid; $friend_request->guid_two = $user1->guid; $friend_request->status = "requested"; $friend_request->requested_by = getLoggedInUserGuid(); $friend_request->save(); new SystemMessage("Your friend request has been sent."); notifyUser("friend", $user2->guid, $user1->guid, $user2->guid); } forward(); } forward(); }
/** * Will we properly try to call the right magic method? * * @dataProvider dataMagic * @param string $method */ public function testMagic($method) { $testOne = new Test_One(); $friend = new Friend($testOne); $badMethod = false; $exception = null; try { switch ($method) { case '__call': $friend->someMethod(); break; case '__get': $friend->someProperty; break; case '__isset': isset($friend->someProperty); break; case '__set': $friend->someProperty = 12; break; case '__unset': unset($friend->someProperty); break; default: $badMethod = true; } } catch (Exception $ex) { $exception = $ex; } if ($badMethod) { $this->fail('Unexpected magic method: ' . $method); } if (is_null($exception)) { $this->fail('Method did not throw an exception'); } $message = $exception->getMessage(); $this->assertEquals('magic ' . $method, $message, 'Method did not throw expected message: ' . $message); }
public static function CreateRequest($from, $to, $message) { $request = new Friend(); $request->User_ID = $from; $request->Friend_User_ID = $to; $request->Status = FriendStatus::AwaitingApproval; $request->RequestMessage = $message; if ($request->save()) { $fromUser = User::model()->findByPk($from); $fromLink = CHtml::link($fromUser->fullName, array('/user/view', 'id' => $from)); Message::SendNotification($to, "Friend request from {$fromLink}", $message, $from, MessageType::FriendRequest); } return $request; }
public function run() { $controller = $this->getController(); $controller->layout = 'main'; $controller->_seoTitle = Yii::t('common', 'User Center') . ' - ' . $controller->_setting['site_name']; //我的好友 $uid = Yii::app()->user->id; $friend_mod = new Friend(); $criteria = new CDbCriteria(); $criteria->condition = 't.user_id=' . $uid; $criteria->order = 't.id DESC'; //分页 $count = $friend_mod->count($criteria); $pages = new CPagination($count); $pages->pageSize = 15; $pages->applyLimit($criteria); $datalist = $friend_mod->findAll($criteria); foreach ((array) $datalist as $k => $v) { $user = User::model()->findByPk($v->friend_user_id); $datalist[$k]['friend_name'] = $user->username; } $controller->render('my_friends', array('datalist' => $datalist, 'pages' => $pages)); }
public static function getFriend($id) { $myfriend = new Friend(); $myfriend->setName("Huỳnh Tuyết Hồng"); $myfriend->setPhoneNumber("8493849815"); $myfriend->setBirthday("2/2/1983"); $myfriend->setAge(26); GWT_RPC::response($myfriend); }
public function run() { $controller = $this->getController(); $controller->layout = 'main'; $this->_setting = $controller->_setting; $this->_stylePath = $controller->_stylePath; $this->_static_public = $controller->_static_public; $this->_seoTitle = Yii::t('common', 'User Center') . ' - ' . $this->_setting['site_name']; //加载css,js Yii::app()->clientScript->registerCssFile($this->_stylePath . "/css/user.css"); Yii::app()->clientScript->registerScriptFile($this->_static_public . "/js/jquery/jquery.js"); //我的好友 $uid = Yii::app()->user->id; $friend_mod = new Friend(); $uid = Yii::app()->user->id; $criteria = new CDbCriteria(); $criteria->condition = 't.uid1=' . $uid . ' OR t.uid2=' . $uid; $criteria->order = 't.id DESC'; //分页 $count = $friend_mod->count($criteria); $pages = new CPagination($count); $pages->pageSize = 15; $criteria->limit = $pages->pageSize; $criteria->offset = $pages->currentPage * $pages->pageSize; $datalist = $friend_mod->findAll($criteria); foreach ((array) $datalist as $k => $v) { if ($v->uid1 == $uid) { $user = User::model()->findByPk($v->uid2); } else { $user = User::model()->findByPk($v->uid1); } $datalist[$k]['friend_name'] = $user->username; $datalist[$k]['friend_id'] = $user->uid; } $controller->render('my_friends', array('datalist' => $datalist, 'pages' => $pages)); }
public static function userFriendsCount($user_id, $is_confirmed = 1, $type = null) { $model = Friend::model(); switch ($type) { case 'in': $count = $model->countByAttributes(['user_a_id' => $user_id, 'is_confirmed' => $is_confirmed]); break; case 'out': $count = $model->countByAttributes(['user_b_id' => $user_id, 'is_confirmed' => $is_confirmed]); break; default: $count = $model->count('(user_a_id = :user_id OR user_b_id = :user_id) AND is_confirmed = :is_confirmed', [':user_id' => $user_id, ':is_confirmed' => $is_confirmed]); break; } return $count; }
public function getFriendsToInvite($uid, $groupId, $start = 0, $limit = 0) { $groupUsers = GroupUser::find("groupId", $groupId)->all(); $result = Friend::find("uid", $uid)->join("user"); if ($groupUsers != null && !empty($groupUsers)) { $where = "[fid] not in("; $args = []; for ($count = count($groupUsers), $i = 0; $i < $count; $i++) { $where .= "?" . ($i < $count - 1 ? "," : ""); $args[] = $groupUsers[$i]->userId; } unset($groupUsers); $where .= ")"; $result = $result->where($where, $args); } return $limit != 0 || $start != 0 ? $result->range($start, $limit) : $result->all(); }
public function login($username, $password) { if (!empty($_COOKIE[COOKIE_NAME]) && !empty($_SESSION['username']) && !empty($_SESSION['user_id']) && $_SESSION['username'] == $username) { return array('r' => 'resume'); } elseif ($user = User::authenticate($username, $password)) { // user just logged in, update login time. ### we do this now in User::authenticate, and also update the ip address ### $user->lastLogin(time()); ### this is problematic !!! ### the hosting application might use these session vars !!! ### either use unique variable names, e.g. imjs_username or ### move this to MySQL.php, so we set these session vars only in the stand-alone ### chat and define a separate function to test if a user is online. The stand-alone chat ### would then test these session vars and the application-specific classes will ### use application-specific functions to check if a user is online. ### Time will tell the wiser after trying it with osDate and joomla. ### A big question is: as the hosting app is performing a login, should ajax-im ### perform a second login, just to set up the data structures? We could handle this ### all with the resume method in the js module. $_SESSION['username'] = $user->username; $_SESSION['user_id'] = $user->user_id; $session_id = md5(microtime(true) . $user->username); $friends = Friend::of($user->user_id); //replaced with $session, to prepare memcache usage $cookie = json_encode(array('user' => $user->username, 'sid' => $session_id)); setcookie(COOKIE_NAME, $cookie, time() + 60 * 60 * 24 * COOKIE_PERIOD, '/', COOKIE_DOMAIN); /* memcache variant (NOT ALL SERVERS MIGHT SUPPORT MEMCACHE) ### not sure if we need to store the friends. friends are updated dynamically with messages or ### restored when the page is loaded. well, maybe we won't need to read the DB on a reload. $session = array( 'username' => $user->username, 'user_id' => intval($user->user_id), 'session_id' => $session_id, 'friends' => Friend::of($user->user_id, true) ); $this->memcache->add($user->username, json_encode($session)); */ ### we could do this in User::authenticate() $status = Status::of($user->user_id); return array('r' => 'logged in', 's' => session_id(), 'u' => $user->username, 's' => $status->status_id, 'f' => $friends, 'x' => COOKIE_NAME . ',' . $cookie . ',' . COOKIE_PERIOD . ',' . COOKIE_DOMAIN); } else { return array('r' => 'error', 'e' => 'invalid user'); } }
public function run() { //We check the level of the user before to allow him to see the content if (isset($this->model->idCategory) && isset($this->filterLevel) && $this->model->idCategory != '') { $levelCategory = Category::model()->findByPk($this->model->idCategory); if ($levelCategory->level > $this->filterLevel) { Yii::app()->user->setFlash('forbiddenLevel', 'Sorry, to have access to this category you need to register a coin which belongs to this category.'); } } //If the user makes a research by username, we shouldn't display the anonymous ones if (isset($this->model->username) && $this->model->username !== '') { $this->model->anonymous = 0; } //We get the generated criterias $criteria = $this->model->getCriteria(); //We set up the number of Truth we want to display if necessary if (isset($this->model->limit)) { $criteria->limit = $this->model->limit; } //We choose the order of display $criteria->order = isset($this->model->order) && $this->model->order !== '' ? $this->model->order . " DESC " : " t.voteUp - t.voteDown DESC "; //Page manager $count = Truth::model()->levelFilter($this->filterLevel)->count($criteria); //Use the $this->limit in Pagination otherwise $pages->pageSize to $criteria overriding the $criteria->limit $pages = new CPagination(isset($this->model->limit) ? $this->model->limit : $count); $pages->pageSize = isset($this->model->limit) ? $this->model->limit : $this->itemsPerPage; $pages->applyLimit($criteria); //Get the datas $datas = Truth::model()->levelFilter($this->filterLevel)->findAll($criteria); //Manage favourites $modelUserList = new UserList(); $userLists = CHtml::listData(array(), 'idUserList', 'name'); if (!Yii::app()->user->isGuest) { $userLists = UserList::model()->findAllByAttributes(array('idUser' => Yii::app()->user->getId())); $userLists = CHtml::listData($userLists, 'idUserList', 'name'); } //Manage send Challenges $friends = CHtml::listData(array(), 'idUser', 'username'); if (!Yii::app()->user->isGuest) { $friends = CHtml::listData(Friend::getFriends(Yii::app()->user->getId()), 'idUser', 'username'); } $this->render('truthList', array('datas' => $datas, 'pages' => $pages, 'userLists' => $userLists, 'friends' => $friends)); }
public function run() { $uid = Yii::app()->user->id; $fuid = $this->fuid; // $friendGroup = Friend::model()->getFriendGroups($uid); if (!empty($friendGroup)) { $groups_arr = CHtml::listData($friendGroup, 'id', 'name'); } $relation = $this->relation; $fuid = $relation->fuid; $list = $relation->frienBelongdGroup; $frienBelongdGroup = array(); if (!empty($list)) { foreach ($list as $key => $value) { $frienBelongdGroup[$value['gid']] = $groups_arr[$value['gid']]; } } $data = array('frienBelongdGroup' => $frienBelongdGroup, 'groups_arr' => $groups_arr, 'friendGroup' => $friendGroup, 'fuid' => $fuid); $this->render('WFriendBelongGroup', $data); }
function fill_smarty($smarty, $type = 'full') { static $link_index = 0; global $current_user, $globals, $the_template, $db, $ranklist; if (!$ranklist) { $users = $db->get_results("SELECT user_karma, COUNT(*) FROM " . table_users . " WHERE user_level NOT IN ('Spammer') AND user_karma>0 GROUP BY user_karma ORDER BY user_karma DESC", ARRAY_N); $ranklist = array(); $rank = 1; if ($users) { foreach ($users as $dbuser) { $ranklist[$dbuser[0]] = $rank; $rank += $dbuser[1]; } } } // DB 08/04/08 if (!is_numeric($this->id)) { return false; } ///// $smarty->assign('link_id', $this->id); if (!$this->read) { return $smarty; } $url = str_replace('&', '&', htmlspecialchars($this->url)); $url_short = txt_shorter($url); if ($this->url == "http://" || $this->url == '') { $url_short = "http://"; } else { $parsed = parse_url($this->url); if (isset($parsed['scheme'])) { $url_short = $parsed['scheme'] . "://" . $parsed['host']; } } echo $parsed['scheme']; $title_short = htmlspecialchars(utf8_wordwrap($this->title, 30, " ", 1)); $smarty->assign('viewtype', $type); $smarty->assign('URL_tagcloud', getmyurl("tagcloud")); $smarty->assign('URL_global_statistics', getmyurl("global_statistics")); $smarty->assign('No_URL_Name', No_URL_Name); if (track_outgoing == true && $url_short != "http://") { if (track_outgoing_method == "id") { $smarty->assign('url', getmyurl("out", $this->id)); } if (track_outgoing_method == "title") { $smarty->assign('url', getmyurl("outtitle", urlencode($this->title_url))); } if (track_outgoing_method == "url") { $smarty->assign('url', getmyurl("outurl", $url)); } } else { $smarty->assign('url', $url); } // DB 11/12/08 if ($url_short == "http://" || $url_short == "://") { $smarty->assign('enc_url', urlencode(my_base_url . $this->get_internal_url())); } else { $smarty->assign('enc_url', urlencode($url)); } ///// $smarty->assign('url_short', $url_short); $smarty->assign('title_short', $title_short); //$smarty->assign('title_url', urlencode($this->title_url)); $smarty->assign('enc_title_short', urlencode($title_short)); $smarty->assign('story_url', $this->get_internal_url()); $smarty->assign('story_edit_url', getmyurl("editlink", $this->id)); $smarty->assign('story_admin_url', getmyurl("admin_modify", $this->id)); $smarty->assign('story_comment_count', $this->comments()); $smarty->assign('story_status', $this->status); //$smarty->assign('story_karma', $this->karma); if ($type == "summary") { if ($this->link_summary == "") { $smarty->assign('story_content', $this->truncate_content()); } else { $smarty->assign('story_content', $this->link_summary); } } /* $sql = "SELECT link_id FROM " . table_links . " WHERE link_category='$id'"; $links = $db->get_results($sql); foreach($links as $link) { $db->query('UPDATE '.table_comments." SET comment_status='discard' WHERE comment_link_id={$link->link_id}"); $vars = array('link_id' => $link->link_id); check_actions('story_discard', $vars); $db->query('UPDATE '.table_links." SET link_status='discard' WHERE link_id={$link->link_id}"); } */ if ($type == "full") { $smarty->assign('story_content', $this->content); $smarty->assign('story_id', $this->id); } if ($this->get_author_info == true) { $smarty->assign('link_submitter', $this->username()); $smarty->assign('submitter_profile_url', getmyurl('user', $this->username)); $smarty->assign('submitter_rank', $ranklist[$this->userkarma]); } $smarty->assign('link_submit_time', $this->date); $smarty->assign('link_submit_timeago', txt_time_diff($this->date)); $smarty->assign('link_submit_date', date('F, d Y g:i A', $this->date)); $smarty->assign('link_published_time', $this->published_date); $smarty->assign('link_published_timeago', txt_time_diff($this->published_date)); $smarty->assign('link_category', $this->category_name()); if (Multiple_Categories) { $cats = array(); foreach ($this->additional_cats as $cat) { $url = $this->category_safe_name($cat); if ($this->status == "published") { $url = getmyurl("maincategory", $url); } if ($this->status == "queued") { $url = getmyurl("queuedcategory", $url); } if ($this->status == "discard") { $url = getmyurl("discardedcategory", $url); } $cats[$url] = $this->category_name($cat); } $smarty->assign('link_additional_cats', $cats); } //assign category id to smarty, so we can use it in the templates. Needed for category colors! $smarty->assign('category_id', $this->category); global $URLMethod; $catvar = $this->category_safe_name(); $smarty->assign('Voting_Method', Voting_Method); $this->votecount = $this->countvotes(); if (Voting_Method == 2) { if (!$this->rating) { $this->rating = $this->rating($this->id) / 2; } $smarty->assign('link_rating', $this->rating); $smarty->assign('link_rating_width', $this->rating * 25); $current_user_id = $current_user->user_id; $jsLink = "vote({$current_user_id}, {$this->id}, {$link_index}, '" . md5($current_user_id . $this->randkey) . "', "; for ($stars = 1; $stars <= 5; $stars++) { $smarty->assign("link_shakebox_javascript_vote_{$stars}star", $jsLink . $stars * 2 . ')'); } $smarty->assign('vote_count', $this->votecount); if ($this->votes($current_user_id) > 0) { $smarty->assign('star_class', "-noh"); } else { $smarty->assign('star_class', ""); } } $smarty->assign('get_group_membered', $this->get_group_membered()); if ($this->status == "published") { $smarty->assign('category_url', getmyurl("maincategory", $catvar)); } if ($this->status == "queued") { $smarty->assign('category_url', getmyurl("queuedcategory", $catvar)); } if ($this->status == "discard") { $smarty->assign('category_url', getmyurl("discardedcategory", $catvar)); } $smarty->assign('trackback_url', get_trackback($this->id)); $smarty->assign('user_logged_in', $current_user->user_login); $smarty->assign('randmd5', md5($current_user->user_id . $this->randkey)); $smarty->assign('user_id', $this->author); $smarty->assign('current_user_id', $current_user_id); if (Enable_Extra_Fields) { $main_smarty = $smarty; include mnminclude . 'extra_fields_smarty.php'; $smarty = $main_smarty; $smarty->assign('link_field1', $this->link_field1); $smarty->assign('link_field2', $this->link_field2); $smarty->assign('link_field3', $this->link_field3); $smarty->assign('link_field4', $this->link_field4); $smarty->assign('link_field5', $this->link_field5); $smarty->assign('link_field6', $this->link_field6); $smarty->assign('link_field7', $this->link_field7); $smarty->assign('link_field8', $this->link_field8); $smarty->assign('link_field9', $this->link_field9); $smarty->assign('link_field10', $this->link_field10); $smarty->assign('link_field11', $this->link_field11); $smarty->assign('link_field12', $this->link_field12); $smarty->assign('link_field13', $this->link_field13); $smarty->assign('link_field14', $this->link_field14); $smarty->assign('link_field15', $this->link_field15); } $smarty->assign('link_group_id', $this->link_group_id); $smarty->assign('Enable_Recommend', Enable_Recommend); $smarty->assign('instpath', my_base_url . my_pligg_base . "/"); $smarty->assign('UseAvatars', do_we_use_avatars()); $smarty->assign('Avatar_ImgSrc', get_avatar('large', "", "", "", $this->userid)); $smarty->assign('Avatar_ImgSrcs', get_avatar('small', "", "", "", $this->userid)); $canIhaveAccess = 0; $canIhaveAccess = $canIhaveAccess + checklevel('god'); $canIhaveAccess = $canIhaveAccess + checklevel('admin'); if ($canIhaveAccess == 1) { $smarty->assign('isadmin', 'yes'); } if ($this->check_friends == true) { // For Friends // include_once mnminclude . 'friend.php'; $friend = new Friend(); // make sure we're logged in and we didnt submit the link. if ($current_user->user_id > 0 && $current_user->user_login != $this->username()) { $friend_md5 = friend_MD5($current_user->user_login, $this->username()); $smarty->assign('FriendMD5', $friend_md5); $isfriend = $friend->get_friend_status($this->author); if (!$isfriend) { $friend_text = 'add to'; $friend_url = 'addfriend'; } else { $friend_text = 'remove from'; $friend_url = 'removefriend'; } $smarty->assign('Friend_Text', $friend_text); $smarty->assign('user_add_remove', getmyurl('user_add_remove', $this->username(), $friend_url)); } $smarty->assign('Allow_Friends', Allow_Friends); // --- // } if ($current_user->user_id != '') { $vars = array('author_id' => $this->author, 'link_id' => $this->id); check_actions('friends_activity_function', $vars); if ($vars['value'] == true) { $smarty->assign('friendvoted', 1); } } /* //for friends voting activity include_once(mnminclude.'friend.php'); $friend = new Friend; $sql = 'SELECT ' . table_votes . '.*, ' . table_users . '.user_id FROM ' . table_votes . ' INNER JOIN ' . table_users . ' ON ' . table_votes . '.vote_user_id = ' . table_users . '.user_id WHERE (((' . table_votes . '.vote_value)>0) AND ((' . table_votes . '.vote_link_id)='.$this->id.') AND (' . table_votes . '.vote_type= "links"));'; $voters = $db->get_results($sql); $voters = object_2_array($voters); foreach($voters as $key => $val) { $voteduserid = $val['user_id']; if($voteduserid == $friend->get_friend_status($this->author)) { $friendvoted = 1; } $smarty->assign('friendvoted', $friendvoted); }*/ if ($this->check_saved == true) { global $cached_saved_links; if (isset($cached_saved_links[$this->id])) { $smarty->assign('link_mine', $cached_saved_links[$this->id]); } else { $smarty->assign('link_mine', $db->get_row("SELECT * FROM " . table_saved_links . " WHERE saved_user_id={$current_user->user_id} AND saved_link_id={$this->id} LIMIT 1;")); } } $smarty->assign('user_url_saved', getmyurl('user2', $current_user->user_login, 'saved')); $smarty->assign('user_add_links_private', getmyurl('user_add_links_private', $this->id)); $smarty->assign('user_add_links_public', getmyurl('user_add_links_public', $this->id)); $smarty->assign('group_story_links_publish', getmyurl('group_story_links_publish', $this->id)); $smarty->assign('group_story_links_queued', getmyurl('group_story_links_queued', $this->id)); $smarty->assign('group_story_links_discard', getmyurl('group_story_links_discard', $this->id)); $smarty->assign('user_url_add_links', getmyurl('user_add_links', $this->id)); $smarty->assign('user_url_remove_links', getmyurl('user_remove_links', $this->id)); $smarty->assign('enable_tags', Enable_Tags); $smarty->assign('link_shakebox_index', $link_index); $smarty->assign('link_shakebox_votes', $this->votes); $smarty->assign('link_shakebox_showbury', $this->reports); $this->get_current_user_votes($current_user->user_id); $smarty->assign('link_shakebox_currentuser_votes', $this->current_user_votes); $smarty->assign('link_shakebox_currentuser_reports', $this->current_user_reports); if ($this->reports == -1) { // reporting was added to the svn and some people started using it // so in upgrade if someone already has the reports field, we set it to // -1. Then when we read() we check if -1. if it still is, update the count // from the votes table and store it into the link_reports field so we // don't have to look at the votes table again. $this->reports = $this->count_all_votes("<0"); $this->store_basic(); $smarty->assign('link_shakebox_reports', $this->reports); } $jslink = "vote({$current_user->user_id},{$this->id},{$link_index}," . "'" . md5($current_user->user_id . $this->randkey) . "',10)"; $jsreportlink = "vote({$current_user->user_id},{$this->id},{$link_index}," . "'" . md5($current_user->user_id . $this->randkey) . "',-10)"; $smarty->assign('link_shakebox_javascript_vote', $jslink); $jsunvote = "unvote({$current_user->user_id},{$this->id},{$link_index}," . "'" . md5($current_user->user_id . $this->randkey) . "',10)"; $smarty->assign('link_shakebox_javascript_unvote', $jsunvote); $smarty->assign('link_shakebox_javascript_report', $jsreportlink); if (!defined('alltagtext')) { // for pages like index, this ->display was being called for each story // which was sometimes 15+ times per page. this way it's just called once $smarty->display('blank.tpl'); //this is just to load the lang file so we can pull from it in php define('alltagtext', $smarty->get_config_vars('PLIGG_Visual_Tags_All_Tags')); } $alltagtext = alltagtext; if (Enable_Tags) { $smarty->assign('tags', $this->tags); if (!empty($this->tags)) { $tags_words = str_replace(", ", ",", $this->tags); $tags_count = substr_count($tags_words, ','); if ($tags_count > 1) { $tags_words = $tags_words; } $tag_array = explode(",", $tags_words); $c = count($tag_array); $tag_array[$c] = $this->tags; $c++; for ($i = 0; $i <= $c; $i++) { if (isset($tag_array[$i])) { if ($URLMethod == 1) { $tags_url_array[$i] = my_pligg_base . "/search.php?search=" . urlencode(trim($tag_array[$i])) . "&tag=true"; } elseif ($URLMethod == 2) { $tags_url_array[$i] = my_pligg_base . "/tag/" . urlencode(trim($tag_array[$i])); } } } $tag_array[$c - 1] = $alltagtext; $smarty->assign('tag_array', $tag_array); $smarty->assign('tags_url_array', $tags_url_array); $tags_url = urlencode($this->tags); $smarty->assign('tags_count', $tags_count); $smarty->assign('tags_words', $tags_words); $smarty->assign('tags_url', $tags_url); } } $smarty->assign('enable_group', enable_group); $smarty->assign('pagename', pagename); $smarty->assign('my_base_url', my_base_url); $smarty->assign('my_pligg_base', my_pligg_base); $smarty->assign('Default_Gravatar_Large', Default_Gravatar_Large); $link_index++; $vars['smarty'] = $smarty; check_actions('lib_link_summary_fill_smarty', $vars); return $smarty; }
public function getSinglePost($slug) { try { $slug = trim($slug); $post = Post::where('slug', $slug)->first(); if (!$post) { $post = Post::findOrFail($slug); return Redirect::to(URL::action('BlogController@getSinglePost', array($post->slug))); } // redirect to relative $id and $slug // if ($slug !== $post->slug) { // return Redirect::to(URL::action ('BlogController@getSinglePost', array($id, $post->slug))); // } /// TODO: check is published // check privacy if (Auth::check()) { if ($post->created_by != Auth::user()->id) { switch ($post->privacy_level) { case Post::_PRIVATE: throw new Exception("Privacy Error"); break; case Post::_FRIEND: $can_see = Friend::where('user_id', $post->created_by)->where('friend_id', Auth::user()->id)->where('type', Friend::ACCEPTED)->first(); if (is_null($can_see)) { throw new Exception("Privacy Error"); } break; case Post::_CUSTOM: $can_see = DB::table('friend_post')->where('post_id', $post->id)->where('friend_id', Auth::user()->id)->first(); if (is_null($can_see)) { throw new Exception("Privacy Error"); } break; case Post::_PUBLIC: default: break; } $post->can_comment = Auth::user()->friendship($post->user) == Friend::ACCEPTED; } } else { if ($post->privacy_level != Post::_PUBLIC) { throw new Exception("Privacy Error"); } $post->can_comment = false; } $tags = $post->tags()->get(); //get comments info $comments = $post->comments()->orderBy('created_at', 'DESC')->simplePaginate(18); $commentsData = new \Illuminate\Database\Eloquent\Collection(); $commentsData = $commentsData->merge($comments); // TODO get all comments then analyze for nested comments foreach ($commentsData as $comment) { if ($comment->parrent_id > 0) { $p = null; foreach ($commentsData as $c) { if ($c->id == $comment->parrent_id) { $p = $c; break; } } if (!$p) { $commentsData = $commentsData->merge($comment->parents()); } } } foreach ($commentsData as $comment) { if ($comment->parrent_id > 0) { foreach ($commentsData as $c) { if ($c->id == $comment->parrent_id) { $c->child_comments[] = $comment; break; } } } } //get user info (who created this post) $post['username'] = $post->user->username; $post['avatar'] = $post->user->image; $this->layout->content = View::make('posts.entry', array('post' => $post, 'comments' => $comments, 'commentsData' => $commentsData, 'tags' => $tags)); } catch (Exception $e) { throw $e; } }