/** * Automatically link username in the provided message when message contains @username * @param $message * @param bool $email * @param bool $usernameOnly only pass username without hyperlink * @return mixed $message A modified copy of the message with the proper hyperlinks or username. */ public static function replaceAliasURL($message, $email = false, $usernameOnly = false) { $pattern = '/@\\[\\[(\\d+):([a-z]+):([^\\]]+)\\]\\]/'; preg_match_all($pattern, $message, $matches); if (isset($matches[1]) && count($matches[1]) > 0) { foreach ($matches[1] as $key => $uid) { $id = CFactory::getUser($uid)->get('id'); $username = $matches[3][$key]; if ($id != 0) { if ($usernameOnly) { $message = CString::str_ireplace($matches[0][$key], $username, $message); } else { $message = CString::str_ireplace($matches[0][$key], CLinkGeneratorHelper::getUserURL($id, $username, $email), $message); } } } } return $message; }
/** * Deprecated since 1.8 * Use CLinkGeneratorHelper::getUserURL instead. */ function cGenerateUserLink($userId, $userName) { return CLinkGeneratorHelper::getUserURL($userId, $userName); }
/** * Automatically link username in the provided message when message contains @username * @param $message * @param bool $email * @param bool $usernameOnly only pass username without hyperlink * @return mixed $message A modified copy of the message with the proper hyperlinks or username. */ public static function replaceAliasURL($message, $email = false, $usernameOnly = false) { $pattern = '/@\\[\\[(\\d+):([a-z]+):([^\\]]+)\\]\\]/'; preg_match_all($pattern, $message, $matches); if (isset($matches[1]) && count($matches[1]) > 0) { foreach ($matches[1] as $key => $uid) { $id = CFactory::getUser($uid)->get('id'); $username = $matches[3][$key]; if ($id != 0) { if ($email) { $profileLink = CRoute::emailLink('index.php?option=com_community&view=profile&userid=' . $id, true); $message = CString::str_ireplace('@' . $username, $profileLink, $message); } elseif ($usernameOnly) { $message = CString::str_ireplace($matches[0][$key], $username, $message); } else { $message = CString::str_ireplace($matches[0][$key], CLinkGeneratorHelper::getUserURL($id, $username), $message); } } } } return $message; }
?> </a> <?php if ($video->groupid) { $group = JTable::getInstance('Group', 'CTable'); $group->load($video->groupid); echo JText::sprintf('COM_COMMUNITY_VIDEOS_FROM_GROUP', '<a href="' . CUrlHelper::groupLink($group->id) . '">' . $group->name . '</a>'); } elseif ($video->eventid) { $event = JTable::getInstance('Event', 'CTable'); $event->load($video->eventid); echo JText::sprintf('COM_COMMUNITY_VIDEOS_FROM_EVENT', '<a href="' . CUrlHelper::eventLink($event->id) . '">' . $event->title . '</a>'); } elseif ($params->get('activity_id')) { $targetUser = CFactory::getUser($params->get('target_id')); ?> ▶ <?php echo CLinkGeneratorHelper::getUserURL($targetUser->id, $targetUser->getDisplayName()); ?> <a href="<?php echo CUrlHelper::streamURI($params->get('activity_id'), $targetUser->id); ?> "><?php echo JText::_('COM_COMMUNITY_SINGULAR_STREAM'); ?> </a> <?php } ?> </small> </li> <?php
/** * Automatically link username in the provided message when message contains @username * * @param $message A string of message that may or may not contain @username * * return $message A modified copy of the message with the proper hyperlinks. **/ public static function replaceAliasURL($message) { $pattern = '/@(("(.*)")|([A-Z0-9][A-Z0-9_-]+)([A-Z0-9][A-Z0-9_-]+))/i'; preg_match_all($pattern, $message, $matches); if (isset($matches[0]) && !empty($matches[0])) { CFactory::load('helpers', 'user'); CFactory::load('helpers', 'linkgenerator'); $usernames = $matches[0]; for ($i = 0; $i < count($usernames); $i++) { $username = $usernames[$i]; $username = CString::str_ireplace('"', '', $username); $username = explode('@', $username); $username = $username[1]; $id = CUserHelper::getUserId($username); if ($id != 0) { $message = CString::str_ireplace($username, CLinkGeneratorHelper::getUserURL($id, $username), $message); } } } return $message; }