BxBaseModProfileFormEntry.php 9.5 KB

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