ItemRef.lua

ItemRef.lua (8.3.0.33095; unchanged since 8.3.0.33062)
  1. local function FormatLink(linkType, linkDisplayText, ...)
  2. local linkFormatTable = { ("|H%s"):format(linkType), ... };
  3. local returnLink = table.concat(linkFormatTable, ":");
  4. if linkDisplayText then
  5. return returnLink .. ("|h%s|h"):format(linkDisplayText);
  6. else
  7. return returnLink .. "|h";
  8. end
  9. end
  10. function SetItemRef(link, text, button, chatFrame)
  11. -- Going forward, use linkType and linkData instead of strsub and strsplit everywhere
  12. local linkType, linkData = ExtractLinkData(link);
  13. if ( strsub(link, 1, 6) == "player" ) then
  14. local namelink, isGMLink, isCommunityLink;
  15. if ( strsub(link, 7, 8) == "GM" ) then
  16. namelink = strsub(link, 10);
  17. isGMLink = true;
  18. elseif ( strsub(link, 7, 15) == "Community") then
  19. namelink = strsub(link, 17);
  20. isCommunityLink = true;
  21. else
  22. namelink = strsub(link, 8);
  23. end
  24. local name, lineID, chatType, chatTarget, communityClubID, communityStreamID, communityEpoch, communityPosition;
  25. if ( isCommunityLink ) then
  26. name, communityClubID, communityStreamID, communityEpoch, communityPosition = strsplit(":", namelink);
  27. else
  28. name, lineID, chatType, chatTarget = strsplit(":", namelink);
  29. end
  30. if ( name and (strlen(name) > 0) ) then
  31. if ( IsModifiedClick("CHATLINK") ) then
  32. local staticPopup;
  33. staticPopup = StaticPopup_Visible("ADD_IGNORE");
  34. if ( staticPopup ) then
  35. -- If add ignore dialog is up then enter the name into the editbox
  36. _G[staticPopup.."EditBox"]:SetText(name);
  37. return;
  38. end
  39. staticPopup = StaticPopup_Visible("ADD_FRIEND");
  40. if ( staticPopup ) then
  41. -- If add ignore dialog is up then enter the name into the editbox
  42. _G[staticPopup.."EditBox"]:SetText(name);
  43. return;
  44. end
  45. staticPopup = StaticPopup_Visible("ADD_GUILDMEMBER");
  46. if ( staticPopup ) then
  47. -- If add ignore dialog is up then enter the name into the editbox
  48. _G[staticPopup.."EditBox"]:SetText(name);
  49. return;
  50. end
  51. staticPopup = StaticPopup_Visible("CHANNEL_INVITE");
  52. if ( staticPopup ) then
  53. _G[staticPopup.."EditBox"]:SetText(name);
  54. return;
  55. end
  56. if ( ChatEdit_GetActiveWindow() ) then
  57. ChatEdit_InsertLink(name);
  58. else
  59. C_FriendList.SendWho(WHO_TAG_EXACT..name);
  60. end
  61. elseif ( button == "RightButton" and (not isGMLink) ) then
  62. FriendsFrame_ShowDropdown(name, 1, lineID, chatType, chatFrame, nil, nil, communityClubID, communityStreamID, communityEpoch, communityPosition);
  63. else
  64. ChatFrame_SendTell(name, chatFrame);
  65. end
  66. end
  67. return;
  68. elseif ( strsub(link, 1, 8) == "BNplayer" ) then
  69. local namelink, isCommunityLink;
  70. if ( strsub(link, 9, 17) == "Community" ) then
  71. namelink = strsub(link, 19);
  72. isCommunityLink = true;
  73. else
  74. namelink = strsub(link, 10);
  75. end
  76. local name, bnetIDAccount, lineID, chatType, chatTarget, communityClubID, communityStreamID, communityEpoch, communityPosition;
  77. if ( isCommunityLink ) then
  78. name, bnetIDAccount, communityClubID, communityStreamID, communityEpoch, communityPosition = strsplit(":", namelink);
  79. else
  80. name, bnetIDAccount, lineID, chatType, chatTarget = strsplit(":", namelink);
  81. end
  82. if ( name and (strlen(name) > 0) ) then
  83. if ( IsModifiedClick("CHATLINK") ) then
  84. -- Disable SHIFT-CLICK for battlenet friends, so we don't put an encoded bnetIDAccount in chat
  85. elseif ( button == "RightButton" ) then
  86. if ( isCommunityLink or not BNIsSelf(bnetIDAccount) ) then
  87. FriendsFrame_ShowBNDropdown(name, 1, nil, chatType, chatFrame, nil, bnetIDAccount, communityClubID, communityStreamID, communityEpoch, communityPosition);
  88. end
  89. else
  90. if ( BNIsFriend(bnetIDAccount)) then
  91. ChatFrame_SendBNetTell(name);
  92. else
  93. local displayName = BNGetDisplayName(bnetIDAccount);
  94. ChatFrame_SendBNetTell(displayName)
  95. end
  96. end
  97. end
  98. return;
  99. elseif ( strsub(link, 1, 7) == "channel" ) then
  100. if ( IsModifiedClick("CHATLINK") ) then
  101. local chanLink = strsub(link, 9);
  102. local chatType, chatTarget = strsplit(":", chanLink);
  103. ChannelFrame:Toggle();
  104. elseif ( button == "LeftButton" ) then
  105. local chanLink = strsub(link, 9);
  106. local chatType, chatTarget = strsplit(":", chanLink);
  107. if ( strupper(chatType) == "CHANNEL" ) then
  108. if ( GetChannelName(tonumber(chatTarget))~=0 ) then
  109. ChatFrame_OpenChat("/"..chatTarget, chatFrame);
  110. end
  111. elseif ( strupper(chatType) == "PET_BATTLE_COMBAT_LOG" or strupper(chatType) == "PET_BATTLE_INFO" ) then
  112. --Don't do anything
  113. else
  114. ChatFrame_OpenChat("/"..chatType, chatFrame);
  115. end
  116. elseif ( button == "RightButton" ) then
  117. local chanLink = strsub(link, 9);
  118. local chatType, chatTarget = strsplit(":", chanLink);
  119. if not ( (strupper(chatType) == "CHANNEL" and GetChannelName(tonumber(chatTarget)) == 0) ) then --Don't show the dropdown if this is a channel we are no longer in.
  120. ChatChannelDropDown_Show(chatFrame, strupper(chatType), chatTarget, Chat_GetColoredChatName(strupper(chatType), chatTarget));
  121. end
  122. end
  123. return;
  124. elseif ( strsub(link, 1, 6) == "GMChat" ) then
  125. GMChatStatusFrame_OnClick();
  126. return;
  127. elseif ( strsub(link, 1, 7) == "levelup" ) then
  128. local _, level, levelUpType, arg1 = strsplit(":", link);
  129. LevelUpDisplay_ShowSideDisplay(tonumber(level), _G[levelUpType], arg1);
  130. return;
  131. elseif ( strsub(link, 1, 6) == "pvpbgs" ) then
  132. TogglePVPUI();
  133. return;
  134. elseif ( strsub(link, 1, 3) == "lfd" ) then
  135. ToggleLFDParentFrame();
  136. return;
  137. elseif ( strsub(link, 1, 8) == "specpane" ) then
  138. ToggleTalentFrame(SPECIALIZATION_TAB);
  139. return;
  140. elseif ( strsub(link, 1, 10) == "talentpane" ) then
  141. ToggleTalentFrame(TALENTS_TAB);
  142. return;
  143. elseif ( strsub(link, 1, 14) == "mountequipment" ) then
  144. ToggleCollectionsJournal(1);
  145. return;
  146. elseif ( strsub(link, 1, 11) == "honortalent" ) then
  147. ToggleTalentFrame(PVP_TALENTS_TAB);
  148. return;
  149. elseif ( strsub(link, 1, 10) == "worldquest" ) then
  150. OpenWorldMap();
  151. return;
  152. elseif ( strsub(link, 1, 7) == "journal" ) then
  153. if ( not HandleModifiedItemClick(GetFixedLink(text)) ) then
  154. if ( not EncounterJournal ) then
  155. EncounterJournal_LoadUI();
  156. end
  157. EncounterJournal_OpenJournalLink(strsplit(":", link));
  158. end
  159. return;
  160. elseif ( strsub(link, 1, 8) == "urlIndex" ) then
  161. local _, index = strsplit(":", link);
  162. LoadURLIndex(tonumber(index));
  163. return;
  164. elseif ( strsub(link, 1, 11) == "lootHistory" ) then
  165. local _, rollID = strsplit(":", link);
  166. LootHistoryFrame_ToggleWithRoll(LootHistoryFrame, tonumber(rollID), chatFrame);
  167. return;
  168. elseif ( strsub(link, 1, 13) == "battlePetAbil" ) then
  169. local _, abilityID, maxHealth, power, speed = strsplit(":", link);
  170. if ( IsModifiedClick() ) then
  171. local fixedLink = GetFixedLink(text);
  172. HandleModifiedItemClick(fixedLink);
  173. else
  174. FloatingPetBattleAbility_Show(tonumber(abilityID), tonumber(maxHealth), tonumber(power), tonumber(speed));
  175. end
  176. return;
  177. elseif ( strsub(link, 1, 9) == "battlepet" ) then
  178. local _, speciesID, level, breedQuality, maxHealth, power, speed, battlePetID = strsplit(":", link);
  179. if ( IsModifiedClick() ) then
  180. local fixedLink = GetFixedLink(text, tonumber(breedQuality));
  181. HandleModifiedItemClick(fixedLink);
  182. else
  183. FloatingBattlePet_Toggle(tonumber(speciesID), tonumber(level), tonumber(breedQuality), tonumber(maxHealth), tonumber(power), tonumber(speed), string.gsub(string.gsub(text, "^(.*)%[", ""), "%](.*)$", ""), battlePetID);
  184. end
  185. return;
  186. elseif ( strsub(link, 1, 19) == "garrfollowerability" ) then
  187. local _, garrFollowerAbilityID = strsplit(":", link);
  188. if ( IsModifiedClick() ) then
  189. local fixedLink = GetFixedLink(text);
  190. HandleModifiedItemClick(fixedLink);
  191. else
  192. FloatingGarrisonFollowerAbility_Toggle(tonumber(garrFollowerAbilityID));
  193. end
  194. return;
  195. elseif ( strsub(link, 1, 12) == "garrfollower" ) then
  196. local _, garrisonFollowerID, quality, level, itemLevel, ability1, ability2, ability3, ability4, trait1, trait2, trait3, trait4, spec1 = strsplit(":", link);
  197. if ( IsModifiedClick() ) then
  198. local fixedLink = GetFixedLink(text, tonumber(quality));
  199. HandleModifiedItemClick(fixedLink);
  200. else
  201. FloatingGarrisonFollower_Toggle(tonumber(garrisonFollowerID), tonumber(quality), tonumber(level), tonumber(itemLevel), tonumber(spec1), tonumber(ability1), tonumber(ability2), tonumber(ability3), tonumber(ability4), tonumber(trait1), tonumber(trait2), tonumber(trait3), tonumber(trait4));
  202. end
  203. return;
  204. elseif ( strsub(link, 1, 11) == "garrmission" ) then
  205. local _, garrMissionID = strsplit(":", link);
  206. local garrMissionID, garrMissionDBID = link:match("garrmission:(%d+):([0-9a-fA-F]+)")
  207. if (garrMissionID and garrMissionDBID and strlen(garrMissionDBID) == 16) then
  208. if ( IsModifiedClick() ) then
  209. local fixedLink = GetFixedLink(text);
  210. HandleModifiedItemClick(fixedLink);
  211. else
  212. FloatingGarrisonMission_Toggle(tonumber(garrMissionID), "0x"..(garrMissionDBID:upper()));
  213. end
  214. end
  215. return;
  216. elseif ( strsub(link, 1, 5) == "death" ) then
  217. local _, id = strsplit(":", link);
  218. OpenDeathRecapUI(id);
  219. return;
  220. elseif ( strsub(link, 1, 7) == "sharess" ) then
  221. local _, index = strsplit(":", link);
  222. SocialFrame_LoadUI();
  223. Social_ShowScreenshot(tonumber(index));
  224. return;
  225. elseif ( strsub(link, 1, 12) == "shareachieve" ) then
  226. local _, achievementID, earned = strsplit(":", link);
  227. SocialFrame_LoadUI();
  228. Social_ShowAchievement(tonumber(achievementID), StringToBoolean(earned));
  229. return;
  230. elseif ( strsub(link, 1, 9) == "shareitem" ) then
  231. local strippedItemLink, earned = link:match("^shareitem:(.-):(%d+)$");
  232. local itemLink = FormatLink("item", nil, strippedItemLink);
  233. SocialFrame_LoadUI();
  234. Social_ShowItem(itemLink, earned);
  235. return;
  236. elseif ( strsub(link, 1, 16) == "transmogillusion" ) then
  237. local fixedLink = GetFixedLink(text);
  238. if ( not HandleModifiedItemClick(fixedLink) ) then
  239. DressUpTransmogLink(link);
  240. end
  241. return;
  242. elseif ( strsub(link, 1, 18) == "transmogappearance" ) then
  243. if ( IsModifiedClick("CHATLINK") ) then
  244. local _, sourceID = strsplit(":", link);
  245. local itemLink = select(6, C_TransmogCollection.GetAppearanceSourceInfo(sourceID));
  246. HandleModifiedItemClick(itemLink);
  247. else
  248. if ( not CollectionsJournal ) then
  249. CollectionsJournal_LoadUI();
  250. end
  251. if ( CollectionsJournal ) then
  252. WardrobeCollectionFrame_OpenTransmogLink(link);
  253. end
  254. end
  255. return;
  256. elseif ( strsub(link, 1, 11) == "transmogset" ) then
  257. if ( not CollectionsJournal ) then
  258. CollectionsJournal_LoadUI();
  259. end
  260. if ( CollectionsJournal ) then
  261. WardrobeCollectionFrame_OpenTransmogLink(link);
  262. end
  263. return;
  264. elseif ( strsub(link, 1, 3) == "api" ) then
  265. APIDocumentation_LoadUI();
  266. local command = APIDocumentation.Commands.Default;
  267. if button == "RightButton" then
  268. command = APIDocumentation.Commands.CopyAPI;
  269. elseif IsModifiedClick("CHATLINK") then
  270. command = APIDocumentation.Commands.OpenDump;
  271. end
  272. APIDocumentation:HandleAPILink(link, command);
  273. return;
  274. elseif ( strsub(link, 1, 13) == "storecategory" ) then
  275. local _, category = strsplit(":", link);
  276. if category == "token" then
  277. StoreFrame_SetTokenCategory();
  278. ToggleStoreUI();
  279. elseif category == "games" then
  280. StoreFrame_OpenGamesCategory();
  281. elseif category == "services" then
  282. StoreFrame_SetServicesCategory();
  283. ToggleStoreUI();
  284. end
  285. elseif ( strsub(link, 1, 4) == "item" ) then
  286. if ( IsModifiedClick("CHATLINK") and button == "LeftButton" ) then
  287. local name, link = GetItemInfo(text);
  288. if ChatEdit_InsertLink(link) then
  289. return;
  290. end
  291. end
  292. elseif ( strsub(link, 1, 10) == "clubTicket" ) then
  293. if ( IsModifiedClick("CHATLINK") and button == "LeftButton" ) then
  294. if ChatEdit_InsertLink(text) then
  295. return;
  296. end
  297. end
  298. local _, ticketId = strsplit(":", link);
  299. if ( CommunitiesFrame_IsEnabled() ) then
  300. Communities_LoadUI();
  301. CommunitiesHyperlink.OnClickLink(ticketId);
  302. end
  303. return;
  304. elseif ( strsub(link, 1, 13) == "calendarEvent" ) then
  305. local _, monthOffset, monthDay, index = strsplit(":", link);
  306. local dayEvent = C_Calendar.GetDayEvent(monthOffset, monthDay, index);
  307. if dayEvent then
  308. Calendar_LoadUI();
  309. if not CalendarFrame:IsShown() then
  310. Calendar_Toggle();
  311. end
  312. C_Calendar.OpenEvent(monthOffset, monthDay, index);
  313. end
  314. return;
  315. elseif ( strsub(link, 1, 9) == "community" ) then
  316. if ( CommunitiesFrame_IsEnabled() ) then
  317. local _, clubId = strsplit(":", link);
  318. clubId = tonumber(clubId);
  319. Communities_LoadUI();
  320. CommunitiesHyperlink.OnClickReference(clubId);
  321. end
  322. return;
  323. elseif ( strsub(link, 1, 9) == "azessence" ) then
  324. if ChatEdit_InsertLink(link) then
  325. return;
  326. end
  327. elseif ( strsub(link, 1, 10) == "clubFinder" ) then
  328. if ( IsModifiedClick("CHATLINK") and button == "LeftButton" ) then
  329. if ChatEdit_InsertLink(text) then
  330. return;
  331. end
  332. end
  333. Communities_LoadUI();
  334. local _, clubFinderId = strsplit(":", link);
  335. CommunitiesFrame:ClubFinderHyperLinkClicked(clubFinderId);
  336. return;
  337. end
  338. if ( IsModifiedClick() ) then
  339. local fixedLink = GetFixedLink(text);
  340. HandleModifiedItemClick(fixedLink);
  341. else
  342. local itemName, itemLink = ItemRefTooltip:GetItem();
  343. if itemLink == GetFixedLink(text) then
  344. HideUIPanel(ItemRefTooltip);
  345. else
  346. ShowUIPanel(ItemRefTooltip);
  347. if ( not ItemRefTooltip:IsShown() ) then
  348. ItemRefTooltip:SetOwner(UIParent, "ANCHOR_PRESERVE");
  349. end
  350. ItemRefTooltip:SetHyperlink(link);
  351. end
  352. end
  353. end
  354. function GetFixedLink(text, quality)
  355. local startLink = strfind(text, "|H");
  356. if ( not strfind(text, "|c") ) then
  357. if ( quality ) then
  358. return (gsub(text, "(|H.+|h.+|h)", ITEM_QUALITY_COLORS[quality].hex.."%1|r", 1));
  359. elseif ( strsub(text, startLink + 2, startLink + 6) == "quest" ) then
  360. --We'll always color it yellow. We really need to fix this for Cata. (It will appear the correct color in the chat log)
  361. return (gsub(text, "(|H.+|h.+|h)", "|cffffff00%1|r", 1));
  362. elseif ( strsub(text, startLink + 2, startLink + 12) == "achievement" ) then
  363. return (gsub(text, "(|H.+|h.+|h)", "|cffffff00%1|r", 1));
  364. elseif ( strsub(text, startLink + 2, startLink + 7) == "talent" ) then
  365. return (gsub(text, "(|H.+|h.+|h)", "|cff4e96f7%1|r", 1));
  366. elseif ( strsub(text, startLink + 2, startLink + 6) == "trade" ) then
  367. return (gsub(text, "(|H.+|h.+|h)", "|cffffd000%1|r", 1));
  368. elseif ( strsub(text, startLink + 2, startLink + 8) == "enchant" ) then
  369. return (gsub(text, "(|H.+|h.+|h)", "|cffffd000%1|r", 1));
  370. elseif ( strsub(text, startLink + 2, startLink + 13) == "instancelock" ) then
  371. return (gsub(text, "(|H.+|h.+|h)", "|cffff8000%1|r", 1));
  372. elseif ( strsub(text, startLink + 2, startLink + 8) == "journal" ) then
  373. return (gsub(text, "(|H.+|h.+|h)", "|cff66bbff%1|r", 1));
  374. elseif ( strsub(text, startLink + 2, startLink + 14) == "battlePetAbil" ) then
  375. return (gsub(text, "(|H.+|h.+|h)", "|cff4e96f7%1|r", 1));
  376. elseif ( strsub(text, startLink + 2, startLink + 10) == "battlepet" ) then
  377. return (gsub(text, "(|H.+|h.+|h)", "|cffffd200%1|r", 1)); -- s_defaultColorString (yellow)
  378. elseif ( strsub(text, startLink + 2, startLink + 12) == "garrmission" ) then
  379. return (gsub(text, "(|H.+|h.+|h)", "|cffffff00%1|r", 1));
  380. elseif ( strsub(text, startLink + 2, startLink + 17) == "transmogillusion" ) then
  381. return (gsub(text, "(|H.+|h.+|h)", "|cffff80ff%1|r", 1));
  382. elseif ( strsub(text, startLink + 2, startLink + 19) == "transmogappearance" ) then
  383. return (gsub(text, "(|H.+|h.+|h)", "|cffff80ff%1|r", 1));
  384. elseif ( strsub(text, startLink + 2, startLink + 12) == "transmogset" ) then
  385. return (gsub(text, "(|H.+|h.+|h)", "|cffff80ff%1|r", 1));
  386. end
  387. end
  388. --Nothing to change.
  389. return text;
  390. end
  391. function GetBattlePetAbilityHyperlink(abilityID, maxHealth, power, speed)
  392. local id, name = C_PetBattles.GetAbilityInfoByID(abilityID);
  393. if not name then
  394. GMError("Attempt to link ability when we don't have record.");
  395. return "";
  396. end
  397. return ("|cff4e96f7%s|r"):format(FormatLink("battlePetAbil", name, abilityID, maxHealth or 100, power or 0, speed or 0));
  398. end
  399. function GetPlayerLink(characterName, linkDisplayText, lineID, chatType, chatTarget)
  400. -- Use simplified link if possible
  401. if lineID or chatType or chatTarget then
  402. return FormatLink("player", linkDisplayText, characterName, lineID or 0, chatType or 0, chatTarget or "");
  403. else
  404. return FormatLink("player", linkDisplayText, characterName);
  405. end
  406. end
  407. function GetBNPlayerLink(name, linkDisplayText, bnetIDAccount, lineID, chatType, chatTarget)
  408. return FormatLink("BNplayer", linkDisplayText, name, bnetIDAccount, lineID or 0, chatType, chatTarget);
  409. end
  410. function GetGMLink(gmName, linkDisplayText, lineID)
  411. if lineID then
  412. return FormatLink("playerGM", linkDisplayText, gmName, lineID or 0);
  413. else
  414. return FormatLink("playerGM", linkDisplayText, gmName);
  415. end
  416. end
  417. local function SanitizeCommunityData(clubId, streamId, epoch, position)
  418. if type(clubId) == "number" then
  419. clubId = ("%.f"):format(clubId);
  420. end
  421. if type(streamId) == "number" then
  422. streamId = ("%.f"):format(streamId);
  423. end
  424. epoch = ("%.f"):format(epoch);
  425. position = ("%.f"):format(position);
  426. return clubId, streamId, epoch, position;
  427. end
  428. function GetBNPlayerCommunityLink(playerName, linkDisplayText, bnetIDAccount, clubId, streamId, epoch, position)
  429. clubId, streamId, epoch, position = SanitizeCommunityData(clubId, streamId, epoch, position);
  430. return FormatLink("BNplayerCommunity", linkDisplayText, playerName, bnetIDAccount, clubId, streamId, epoch, position);
  431. end
  432. function GetPlayerCommunityLink(playerName, linkDisplayText, clubId, streamId, epoch, position)
  433. clubId, streamId, epoch, position = SanitizeCommunityData(clubId, streamId, epoch, position);
  434. return FormatLink("playerCommunity", linkDisplayText, playerName, clubId, streamId, epoch, position);
  435. end
  436. function GetClubTicketLink(ticketId, clubName, clubType)
  437. local link = FormatLink("clubTicket", CLUB_INVITE_HYPERLINK_TEXT:format(clubName), ticketId);
  438. if clubType == Enum.ClubType.BattleNet then
  439. return BATTLENET_FONT_COLOR:WrapTextInColorCode(link);
  440. else
  441. return NORMAL_FONT_COLOR:WrapTextInColorCode(link);
  442. end
  443. end
  444. function GetClubFinderLink(clubFinderId, clubName)
  445. local clubType = C_ClubFinder.GetClubTypeFromFinderGUID(clubFinderId);
  446. local fontColor = NORMAL_FONT_COLOR;
  447. local linkGlobalString;
  448. if(clubType == Enum.ClubFinderRequestType.Guild) then
  449. linkGlobalString = CLUB_FINDER_LINK_GUILD;
  450. elseif(clubType == Enum.ClubFinderRequestType.Community) then
  451. linkGlobalString = CLUB_FINDER_LINK_COMMUNITY;
  452. fontColor = BATTLENET_FONT_COLOR;
  453. else
  454. linkGlobalString = ""
  455. end
  456. return fontColor:WrapTextInColorCode(FormatLink("clubFinder", linkGlobalString:format(clubName), clubFinderId));
  457. end
  458. function GetCalendarEventLink(monthOffset, monthDay, index)
  459. local dayEvent = C_Calendar.GetDayEvent(monthOffset, monthDay, index);
  460. if dayEvent then
  461. return FormatLink("calendarEvent", dayEvent.title, monthOffset, monthDay, index);
  462. end
  463. return nil;
  464. end
  465. function GetCommunityLink(clubId)
  466. local clubInfo = C_Club.GetClubInfo(clubId);
  467. if clubInfo then
  468. local link = FormatLink("community", COMMUNITY_REFERENCE_FORMAT:format(clubInfo.name), clubId);
  469. if clubInfo.clubType == Enum.ClubType.BattleNet then
  470. return BATTLENET_FONT_COLOR:WrapTextInColorCode(link);
  471. else
  472. return NORMAL_FONT_COLOR:WrapTextInColorCode(link);
  473. end
  474. end
  475. return nil;
  476. end
  477. LinkUtil = {};
  478. function LinkUtil.SplitLink(link) -- returns linkText and displayText
  479. return link:match("^|H(.+)|h(.*)|h$");
  480. end
  481. -- Extract the first link from the text given, ignoring leading and trailing characters.
  482. -- returns linkType, linkOptions, displayText
  483. function LinkUtil.ExtractLink(text)
  484. -- linkType: |H([^:]*): matches everything that's not a colon, up to the first colon.
  485. -- linkOptions: ([^|]*)|h matches everything that's not a |, up to the first |h.
  486. -- displayText: ([^|]*)|h matches everything that's not a |, up to the second |h.
  487. -- Ex: |cffffffff|Htype:a:b:c:d|htext|h|r becomes type, a:b:c:d, text
  488. return string.match(text, [[|H([^:]*):([^|]*)|h([^|]*)|h]]);
  489. end
  490. function LinkUtil.IsLinkType(link, matchLinkType)
  491. local linkType, linkOptions, displayText = LinkUtil.ExtractLink(link);
  492. return linkType == matchLinkType;
  493. end