PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/components/bitrix/socialnetwork.user_birthday/component.php

https://gitlab.com/alexprowars/bitrix
PHP | 157 lines | 116 code | 26 blank | 15 comment | 32 complexity | 0638220b9aa3c36667432a4060c4844c MD5 | raw file
  1. <?php
  2. if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true)
  3. {
  4. die();
  5. }
  6. /** @var CBitrixComponent $this */
  7. /** @var array $arParams */
  8. /** @var array $arResult */
  9. /** @global CMain $APPLICATION */
  10. /** @global CUser $USER */
  11. use Bitrix\Socialnetwork\ComponentHelper;
  12. if (!CModule::IncludeModule("socialnetwork"))
  13. {
  14. ShowError(GetMessage("SONET_MODULE_NOT_INSTALL"));
  15. return;
  16. }
  17. $arParams["USER_ID"] = intval($arParams["USER_ID"]);
  18. if ($arParams["USER_ID"] <= 0)
  19. $arParams["USER_ID"] = intval($USER->GetID());
  20. $arParams["SET_NAV_CHAIN"] = ($arParams["SET_NAV_CHAIN"] === "N" ? "N" : "Y");
  21. if ($arParams["USER_VAR"] == '')
  22. $arParams["USER_VAR"] = "user_id";
  23. if ($arParams["PAGE_VAR"] == '')
  24. $arParams["PAGE_VAR"] = "page";
  25. $arParams["PATH_TO_USER"] = trim($arParams["PATH_TO_USER"]);
  26. if ($arParams["PATH_TO_USER"] == '')
  27. $arParams["PATH_TO_USER"] = htmlspecialcharsbx($APPLICATION->GetCurPage()."?".$arParams["PAGE_VAR"]."=user&".$arParams["USER_VAR"]."=#user_id#");
  28. $arParams["ITEMS_COUNT"] = intval($arParams["ITEMS_COUNT"]);
  29. if ($arParams["ITEMS_COUNT"] <= 0)
  30. $arParams["ITEMS_COUNT"] = 6;
  31. $tooltipParams = ComponentHelper::checkTooltipComponentParams($arParams);
  32. $arParams['SHOW_FIELDS_TOOLTIP'] = $tooltipParams['SHOW_FIELDS_TOOLTIP'];
  33. $arParams['USER_PROPERTY_TOOLTIP'] = $tooltipParams['USER_PROPERTY_TOOLTIP'];
  34. if (CSocNetUser::IsFriendsAllowed())
  35. {
  36. if ($arParams["USER_ID"] > 0)
  37. {
  38. $dbUser = CUser::GetByID($arParams["USER_ID"]);
  39. $arResult["User"] = $dbUser->GetNext();
  40. if (!is_array($arResult["User"]))
  41. {
  42. $arResult["FatalError"] = GetMessage("SONET_P_USER_NO_USER").". ";
  43. }
  44. else
  45. {
  46. $arResult["CurrentUserPerms"] = CSocNetUserPerms::InitUserPerms($GLOBALS["USER"]->GetID(), $arResult["User"]["ID"], CSocNetUser::IsCurrentUserModuleAdmin());
  47. /*
  48. if ($arParams["SET_TITLE"] == "Y")
  49. $APPLICATION->SetTitle($arResult["User"]["NAME"]." ".$arResult["User"]["LAST_NAME"].": ".GetMessage("SONET_C33_PAGE_TITLE"));
  50. if ($arParams["SET_NAV_CHAIN"] != "N")
  51. {
  52. $APPLICATION->AddChainItem($arResult["User"]["NAME"]." ".$arResult["User"]["LAST_NAME"], CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_USER"], array("user_id" => $arResult["User"]["ID"])));
  53. $APPLICATION->AddChainItem(GetMessage("SONET_C33_PAGE_TITLE"));
  54. }
  55. */
  56. if ($arResult["CurrentUserPerms"] && $arResult["CurrentUserPerms"]["Operations"]["viewprofile"] && $arResult["CurrentUserPerms"]["Operations"]["viewfriends"])
  57. {
  58. $arNavParams = array("nPageSize" => $arParams["ITEMS_COUNT"], "bDescPageNumbering" => false);
  59. $arNavigation = CDBResult::GetNavParams($arNavParams);
  60. $nowDay = intval(Date("d"));
  61. $nowMonth = intval(Date("m"));
  62. $arResult["Users"] = false;
  63. $cnt = 0;
  64. $dbFriends = CSocNetUserRelations::GetListBirthday($arResult["User"]["ID"], 0);
  65. if ($dbFriends)
  66. {
  67. $arResult["Users"] = array();
  68. $arResult["Users"]["List"] = false;
  69. while ($arFriends = $dbFriends->GetNext())
  70. {
  71. if ($arFriends["PB"] == '')
  72. continue;
  73. $pu = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_USER"], array("user_id" => $arFriends["ID"]));
  74. $canViewProfile = CSocNetUserPerms::CanPerformOperation($GLOBALS["USER"]->GetID(), $arFriends["ID"], "viewprofile", CSocNetUser::IsCurrentUserModuleAdmin());
  75. if (intval($arParams["THUMBNAIL_LIST_SIZE"]) > 0)
  76. {
  77. if (intval($arFriends["PERSONAL_PHOTO"]) <= 0)
  78. {
  79. switch ($arFriends["PERSONAL_GENDER"])
  80. {
  81. case "M":
  82. $suffix = "male";
  83. break;
  84. case "F":
  85. $suffix = "female";
  86. break;
  87. default:
  88. $suffix = "unknown";
  89. }
  90. $arFriends["PERSONAL_PHOTO"] = COption::GetOptionInt("socialnetwork", "default_user_picture_".$suffix, false, SITE_ID);
  91. }
  92. $arImage = CSocNetTools::InitImage($arFriends["PERSONAL_PHOTO"], $arParams["THUMBNAIL_LIST_SIZE"], "/bitrix/images/socialnetwork/nopic_30x30.gif", 30, $pu, $canViewProfile);
  93. }
  94. else // old
  95. $arImage = CSocNetTools::InitImage($arFriends["PERSONAL_PHOTO"], 50, "/bitrix/images/socialnetwork/nopic_user_50.gif", 50, $pu, $canViewProfile);
  96. $arDateTmp = ParseDateTime($arFriends["PB"], "YYYY-MM-DD");
  97. $day = intval($arDateTmp["DD"]);
  98. $month = intval($arDateTmp["MM"]);
  99. $year = intval($arDateTmp["YYYY"]);
  100. if ($day <= 0)
  101. continue;
  102. if ($arResult["Users"]["List"] == false)
  103. $arResult["Users"]["List"] = array();
  104. $val = $day.' '.ToLower(GetMessage('MONTH_'.$month.'_S'));
  105. $arResult["Users"]["List"][] = array(
  106. "ID" => $arFriends["ID"],
  107. "NAME" => $arFriends["NAME"],
  108. "LAST_NAME" => $arFriends["LAST_NAME"],
  109. "SECOND_NAME" => $arFriends["SECOND_NAME"],
  110. "LOGIN" => $arFriends["LOGIN"],
  111. "PERSONAL_PHOTO" => $arFriends["PERSONAL_PHOTO"],
  112. "PERSONAL_PHOTO_FILE" => $arImage["FILE"],
  113. "PERSONAL_PHOTO_IMG" => $arImage["IMG"],
  114. "PROFILE_URL" => $pu,
  115. "SHOW_PROFILE_LINK" => $canViewProfile,
  116. "BIRTHDAY" => $val,
  117. "NOW" => ($nowDay == $day && $nowMonth == $month),
  118. "IS_ONLINE" => ($arFriends["IS_ONLINE"] === "Y")
  119. );
  120. $cnt++;
  121. if ($cnt > $arParams["ITEMS_COUNT"])
  122. break;
  123. }
  124. $arResult["NAV_STRING"] = $dbFriends->GetPageNavStringEx($navComponentObject, GetMessage("SONET_C33_NAV"), "", false);
  125. }
  126. }
  127. }
  128. }
  129. $this->IncludeComponentTemplate();
  130. }