1
0

BxBaseModProfileFormEntry.php 9.5 KB

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