public static function _getMutualFriendsHTML($userid = null) { $my = CFactory::getUser(); if ($my->id == $userid) { return; } $friendsModel = CFactory::getModel('Friends'); $friends = $friendsModel->getFriends($userid, 'latest', false, 'mutual'); $html = "<ul class='joms-list--friend single-column'>"; if (sizeof($friends)) { foreach ($friends as $friend) { $html .= "<li class='joms-list__item'>"; $html .= "<div class='joms-list__avatar'>"; $html .= '<div class="joms-avatar ' . CUserHelper::onlineIndicator($friend) . '"><a href="' . CRoute::_('index.php?option=com_community&view=profile&userid=' . $friend->id) . '">'; $html .= '<img src="' . $friend->getThumbAvatar() . '" data-author="' . $friend->id . '" />'; $html .= "</a></div></div>"; $html .= "<div class='joms-list__body'>"; $html .= CFriendsHelper::getUserCog($friend->id, null, null, true); $html .= CFriendsHelper::getUserFriendDropdown($friend->id); $html .= '<a href="' . CRoute::_('index.php?option=com_community&view=profile&userid=' . $friend->id) . '">'; $html .= '<h4 class="joms-text--username">' . $friend->getDisplayName() . '</h4></a>'; $html .= '<span class="joms-text--title">' . JText::sprintf('COM_COMMUNITY_TOTAL_MUTUAL_FRIENDS', CFriendsHelper::getTotalMutualFriends($friend->id)) . '</span>'; $html .= "</div></li>"; } $html .= "</ul>"; } else { $html .= JText::_('COM_COMMUNITY_NO_MUTUAL_FRIENDS'); } return $html; }
<div class="joms-list__body"> <a href="<?php echo $user->profileLink; ?> "><h4 class="joms-text--username"><?php echo $user->getDisplayName(); ?> </h4></a> <span class="joms-text--title"><?php echo JText::sprintf('COM_COMMUNITY_TOTAL_MUTUAL_FRIENDS', CFriendsHelper::getTotalMutualFriends($user->id)); ?> </span> </div> <div class="joms-list__actions"> <?php echo CFriendsHelper::getUserCog($user->id, null, null, true); ?> <?php echo CFriendsHelper::getUserFriendDropdown($user->id); ?> </div> </li> <?php } ?> </ul> </div> <?php }
/** * Ajax function to approve a friend request **/ public function ajaxApproveRequest($requestId) { $filter = JFilterInput::getInstance(); $my = CFactory::getUser(); $friendsModel = CFactory::getModel('friends'); $requestId = $filter->clean($requestId, 'int'); $json = array(); if ($my->id == 0) { return $this->ajaxBlockUnregister(); } if ($friendsModel->isMyRequest($requestId, $my->id)) { $connected = $friendsModel->approveRequest($requestId); if ($connected) { $act = new stdClass(); $act->cmd = 'friends.request.approve'; $act->actor = $connected[0]; $act->target = $connected[1]; $act->title = ''; //JText::_('COM_COMMUNITY_ACTIVITY_FRIENDS_NOW'); $act->content = ''; $act->app = 'friends.connect'; $act->cid = 0; //add user points - give points to both parties //CFactory::load( 'libraries' , 'userpoints' ); if (CUserPoints::assignPoint('friends.request.approve')) { CActivityStream::add($act); } $friendId = $connected[0] == $my->id ? $connected[1] : $connected[0]; $friend = CFactory::getUser($friendId); $friendUrl = CRoute::_('index.php?option=com_community&view=profile&userid=' . $friendId); CUserPoints::assignPoint('friends.request.approve', $friendId); // need to both user's friend list $friendsModel->updateFriendCount($my->id); $friendsModel->updateFriendCount($friendId); $params = new CParameter(''); $params->set('url', 'index.php?option=com_community&view=profile&userid=' . $my->id); $params->set('friend', $my->getDisplayName()); $params->set('friend_url', 'index.php?option=com_community&view=profile&userid=' . $my->id); CNotificationLibrary::add('friends_create_connection', $my->id, $friend->id, JText::_('COM_COMMUNITY_FRIEND_REQUEST_APPROVED'), '', 'friends.approve', $params); $json['success'] = true; $json['message'] = JText::sprintf('COM_COMMUNITY_FRIEND_REQUEST_ACCEPTED', $friend->getDisplayName(), $friendUrl); $json['display'] = CFriendsHelper::getUserFriendDropdown($friendId); //trigger for onFriendApprove $eventObject = new stdClass(); $eventObject->profileOwnerId = $my->id; $eventObject->friendId = $friendId; $this->triggerFriendEvents('onFriendApprove', $eventObject); unset($eventObject); } } else { $json['error'] = JText::_('COM_COMMUNITY_FRIENDS_NOT_YOUR_REQUEST'); } $this->cacheClean(array(COMMUNITY_CACHE_TAG_ACTIVITIES)); die(json_encode($json)); }