BxBaseModProfileFormEntry.php 9.2 KB

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