BxBaseModProfileFormEntry.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup BaseProfile Base classes for profile modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Create/edit profile form.
  13. */
  14. class BxBaseModProfileFormEntry extends BxBaseModGeneralFormEntry
  15. {
  16. protected $_iAccountProfileId = 0;
  17. protected $_aImageFields = array ();
  18. public function __construct($aInfo, $oTemplate = false)
  19. {
  20. if (!isset($this->_bAllowChangeUserForAdmins))
  21. $this->_bAllowChangeUserForAdmins = false;
  22. parent::__construct($aInfo, $oTemplate);
  23. $this->_sAuthorKey = 'profile_id';
  24. $CNF = &$this->_oModule->_oConfig->CNF;
  25. if (!empty($CNF['FIELD_PICTURE']) && isset($this->aInputs[$CNF['FIELD_PICTURE']])) {
  26. $this->_aImageFields[$CNF['FIELD_PICTURE']] = array (
  27. 'storage_object' => $CNF['OBJECT_STORAGE'],
  28. 'images_transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_THUMB'],
  29. 'uploaders' => $CNF['OBJECT_UPLOADERS_PICTURE'],
  30. );
  31. }
  32. if (!empty($CNF['FIELD_COVER']) && isset($this->aInputs[$CNF['FIELD_COVER']])) {
  33. $this->_aImageFields[$CNF['FIELD_COVER']] = array (
  34. 'storage_object' => $CNF['OBJECT_STORAGE_COVER'],
  35. 'images_transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_COVER_THUMB'],
  36. 'uploaders' => $CNF['OBJECT_UPLOADERS_COVER'],
  37. );
  38. }
  39. foreach ($this->_aImageFields as $sField => $aParams) {
  40. $this->aInputs[$sField]['storage_object'] = $aParams['storage_object'];
  41. $this->aInputs[$sField]['uploaders'] = !empty($this->aInputs[$sField]['value']) ? unserialize($this->aInputs[$sField]['value']) : $aParams['uploaders'];
  42. $this->aInputs[$sField]['images_transcoder'] = $aParams['images_transcoder'];
  43. $this->aInputs[$sField]['storage_private'] = 0;
  44. $this->aInputs[$sField]['multiple'] = false;
  45. $this->aInputs[$sField]['content_id'] = 0;
  46. $this->aInputs[$sField]['ghost_template'] = '';
  47. }
  48. $oAccountProfile = BxDolProfile::getInstanceAccountProfile();
  49. if ($oAccountProfile)
  50. $this->_iAccountProfileId = $oAccountProfile->id();
  51. }
  52. function initChecker ($aValues = array (), $aSpecificValues = array())
  53. {
  54. $CNF = &$this->_oModule->_oConfig->CNF;
  55. $aContentInfo = isset($CNF['FIELD_ID']) && isset($aValues[$CNF['FIELD_ID']]) ? $this->_oModule->_oDb->getContentInfoById ($aValues[$CNF['FIELD_ID']]) : array();
  56. foreach ($this->_aImageFields as $sField => $aParams) {
  57. if ($aValues && !empty($aValues[$CNF['FIELD_ID']]))
  58. $this->aInputs[$sField]['content_id'] = $aValues[$CNF['FIELD_ID']];
  59. $this->aInputs[$sField]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName('form_ghost_template.html', $this->_getProfilePhotoGhostTmplVars($sField, $aContentInfo));
  60. }
  61. parent::initChecker($aValues, $aSpecificValues);
  62. }
  63. function delete ($iContentId, $aContentInfo = array())
  64. {
  65. $CNF = &$this->_oModule->_oConfig->CNF;
  66. $iProfileId = $this->getContentOwnerProfileId($iContentId);
  67. foreach ($this->_aImageFields as $sField => $aParams) {
  68. $oStorage = BxDolStorage::getObjectInstance($aParams['storage_object']);
  69. $aFiles = $oStorage->getGhosts($iProfileId, $iContentId);
  70. foreach ($aFiles as $aFile) {
  71. if (!$oStorage->getFile($aFile['id']))
  72. continue;
  73. $bRet = $oStorage->deleteFile($aFile['id'], $this->_iAccountProfileId);
  74. }
  75. }
  76. return parent::delete($iContentId, $aContentInfo);
  77. }
  78. protected function genCustomViewRowValueProfileEmail($aInput)
  79. {
  80. return $this->genCustomViewRowValueProfileEmailOrIp($aInput);
  81. }
  82. protected function genCustomViewRowValueProfileIp($aInput)
  83. {
  84. return $this->genCustomViewRowValueProfileEmailOrIp($aInput);
  85. }
  86. protected function genCustomViewRowValueFriendsCount($aInput)
  87. {
  88. if (isset($this->_oModule->_oConfig->CNF['URI_VIEW_FRIENDS'])){
  89. $oProfile = $this->_oModule->getProfileByCurrentUrl();
  90. if ($oProfile){
  91. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_friends');
  92. $iCount = $oConnection->getConnectedContentCount($oProfile->id(), true);
  93. return $this->_oModule->_oTemplate->parseHtmlByName('name_link.html', array(
  94. 'href' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $this->_oModule->_oConfig->CNF['URI_VIEW_FRIENDS'] . '&profile_id=' . $oProfile->id()),
  95. 'title' => '',
  96. 'content' => $iCount
  97. ));
  98. }
  99. }
  100. return '';
  101. }
  102. protected function genCustomViewRowValueFollowersCount($aInput)
  103. {
  104. if (isset($this->_oModule->_oConfig->CNF['URI_VIEW_SUBSCRIPTIONS'])){
  105. $oProfile = $this->_oModule->getProfileByCurrentUrl();
  106. if ($oProfile){
  107. $oConnectionFollow = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  108. $iCount = $oConnectionFollow->getConnectedInitiatorsCount($oProfile->id());
  109. return $this->_oModule->_oTemplate->parseHtmlByName('name_link.html', array(
  110. 'href' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $this->_oModule->_oConfig->CNF['URI_VIEW_SUBSCRIPTIONS'] . '&profile_id=' . $oProfile->id()),
  111. 'title' => '',
  112. 'content' => $iCount
  113. ));
  114. }
  115. }
  116. return '';
  117. }
  118. private function genCustomViewRowValueProfileEmailOrIp($aInput)
  119. {
  120. $CNF = &$this->_oModule->_oConfig->CNF;
  121. if(empty($aInput['value']))
  122. return '';
  123. $sValue = $aInput['value'];
  124. $sModuleAccounts = 'bx_accounts';
  125. if(!BxDolModuleQuery::getInstance()->isEnabledByName($sModuleAccounts))
  126. return $sValue;
  127. $oModuleAccounts = BxDolModule::getInstance($sModuleAccounts);
  128. if(!$oModuleAccounts || empty($oModuleAccounts->_oConfig->CNF['URL_MANAGE_ADMINISTRATION']))
  129. return $sValue;
  130. return $this->_oModule->_oTemplate->parseHtmlByName('name_link.html', array(
  131. 'href' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($oModuleAccounts->_oConfig->CNF['URL_MANAGE_ADMINISTRATION'], array(
  132. 'filter' => urlencode($sValue)
  133. )),
  134. 'title' => '',
  135. 'content' => $sValue
  136. ));
  137. }
  138. protected function genCustomViewRowValueProfileStatus($aInput)
  139. {
  140. $CNF = &$this->_oModule->_oConfig->CNF;
  141. if(empty($aInput['value']))
  142. return '';
  143. $sStatus = _t('_sys_profile_status_' . $aInput['value']);
  144. if(empty($CNF['URL_MANAGE_ADMINISTRATION']) || empty($CNF['FIELD_TITLE']) || empty($this->aInputs[$CNF['FIELD_TITLE']]['value']))
  145. return $sStatus;
  146. return $this->_oModule->_oTemplate->parseHtmlByName('name_link.html', array(
  147. 'href' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_MANAGE_ADMINISTRATION'], array(
  148. 'filter' => urlencode($this->aInputs[$CNF['FIELD_TITLE']]['value'])
  149. )),
  150. 'title' => '',
  151. 'content' => $sStatus
  152. ));
  153. }
  154. protected function _associalFileWithContent($oStorage, $iFileId, $iProfileId, $iContentId, $sPictureField = '')
  155. {
  156. $oStorage->updateGhostsContentId ($iFileId, $iProfileId, $iContentId, $this->_isAdmin($iContentId));
  157. $bResult = (int)$this->_oModule->_oDb->updateContentPictureById($iContentId, 0/*$iProfileId*/, $iFileId, $sPictureField) > 0;
  158. if(!$bResult)
  159. return;
  160. $CNF = &$this->_oModule->_oConfig->CNF;
  161. $aField2Method = [
  162. $CNF['FIELD_PICTURE'] => 'picture',
  163. $CNF['FIELD_COVER'] => 'cover',
  164. ];
  165. if(!empty($aField2Method[$sPictureField]))
  166. bx_alert($this->_oModule->getName(), 'profile_' . $aField2Method[$sPictureField] . '_changed', $iFileId, $iProfileId, [
  167. 'object_author_id' => $iProfileId,
  168. 'content' => $iContentId,
  169. 'field' => $sPictureField
  170. ]);
  171. }
  172. protected function _getProfilePhotoGhostTmplVars($sField, $aContentInfo = array())
  173. {
  174. $CNF = &$this->_oModule->_oConfig->CNF;
  175. return array (
  176. 'name' => $this->aInputs[$sField]['name'],
  177. 'content_id' => $this->aInputs[$sField]['content_id'],
  178. 'bx_if:set_thumb' => array (
  179. 'condition' => false,
  180. 'content' => array (),
  181. ),
  182. );
  183. }
  184. protected function _isAdmin ($iContentId = 0)
  185. {
  186. if (parent::_isAdmin ($iContentId))
  187. return true;
  188. if (!$iContentId || !($aDataEntry = $this->_oModule->_oDb->getContentInfoById((int)$iContentId)))
  189. return false;
  190. return CHECK_ACTION_RESULT_ALLOWED == $this->_oModule->checkAllowedEdit ($aDataEntry);
  191. }
  192. protected function _getPrivacyFields($aKeysF2O = array())
  193. {
  194. if(empty($aKeysF2O))
  195. $aKeysF2O = array(
  196. 'FIELD_ALLOW_VIEW_TO' => 'OBJECT_PRIVACY_VIEW',
  197. 'FIELD_ALLOW_POST_TO' => 'OBJECT_PRIVACY_POST',
  198. 'FIELD_ALLOW_CONTACT_TO' => 'OBJECT_PRIVACY_CONTACT'
  199. );
  200. return parent::_getPrivacyFields($aKeysF2O);
  201. }
  202. }
  203. /** @} */