BxBaseServices.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * System services.
  11. */
  12. class BxBaseServices extends BxDol implements iBxDolProfileService
  13. {
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. }
  18. public function serviceProfileUnit ($iContentId, $aParams = array())
  19. {
  20. return $this->_serviceProfileFunc('getUnit', $iContentId);
  21. }
  22. public function serviceHasImage ($iContentId)
  23. {
  24. return false;
  25. }
  26. public function serviceProfilePicture ($iContentId)
  27. {
  28. return $this->_serviceProfileFunc('getPicture', $iContentId);
  29. }
  30. public function serviceProfileAvatar ($iContentId)
  31. {
  32. return $this->_serviceProfileFunc('getAvatar', $iContentId);
  33. }
  34. public function serviceProfileEditUrl ($iContentId)
  35. {
  36. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=account-settings-info');
  37. }
  38. public function serviceProfileThumb ($iContentId)
  39. {
  40. return $this->_serviceProfileFunc('getThumb', $iContentId);
  41. }
  42. public function serviceProfileIcon ($iContentId)
  43. {
  44. return $this->_serviceProfileFunc('getIcon', $iContentId);
  45. }
  46. public function serviceProfileName ($iContentId)
  47. {
  48. return $this->_serviceProfileFunc('getDisplayName', $iContentId);
  49. }
  50. public function serviceProfileUrl ($iContentId)
  51. {
  52. return $this->_serviceProfileFunc('getUrl', $iContentId);
  53. }
  54. /**
  55. * @see iBxDolProfileService::serviceCheckAllowedProfileView
  56. */
  57. public function serviceCheckAllowedProfileView($iContentId)
  58. {
  59. return _t('_Access denied');
  60. }
  61. /**
  62. * @see iBxDolProfileService::serviceCheckAllowedPostInProfile
  63. */
  64. public function serviceCheckAllowedPostInProfile($iContentId)
  65. {
  66. return _t('_Access denied');
  67. }
  68. public function serviceFormsHelper ()
  69. {
  70. return new BxTemplAccountForms();
  71. }
  72. public function serviceActAsProfile ()
  73. {
  74. return false;
  75. }
  76. public function servicePrepareFields ($aFieldsProfile)
  77. {
  78. return $aFieldsProfile;
  79. }
  80. public function serviceProfilesSearch ($sTerm, $iLimit)
  81. {
  82. $oDb = BxDolAccountQuery::getInstance();
  83. $aRet = array();
  84. $a = $oDb->searchByTerm($sTerm, $iLimit);
  85. foreach ($a as $r)
  86. $aRet[] = array ('label' => $this->serviceProfileName($r['content_id']), 'value' => $r['profile_id']);
  87. return $aRet;
  88. }
  89. public function _serviceProfileFunc ($sFunc, $iContentId)
  90. {
  91. if (!$iContentId)
  92. return false;
  93. if (!($oAccount = BxDolAccount::getInstance($iContentId)))
  94. return false;
  95. return $oAccount->$sFunc();
  96. }
  97. public function serviceAlertResponseProcessInstalled()
  98. {
  99. BxDolTranscoderImage::registerHandlersSystem();
  100. }
  101. public function serviceAlertResponseProcessStorageChange ($oAlert)
  102. {
  103. if ('sys_storage_default' != $oAlert->aExtras['option'])
  104. return;
  105. $aStorages = BxDolStorageQuery::getStorageObjects();
  106. foreach ($aStorages as $r) {
  107. if (0 == $r['current_size'] && 0 == $r['current_number'] && ($oStorage = BxDolStorage::getObjectInstance($r['object'])))
  108. $oStorage->changeStorageEngine($oAlert->aExtras['value']);
  109. }
  110. }
  111. /**
  112. * This service adds notification for users which open your site on mobile devices
  113. * and suggest to add your site to their mobile homepage.
  114. */
  115. public function serviceAddToMobileHomepage ()
  116. {
  117. BxDolTemplate::getInstance()->addJs('cubiq-add-to-homescreen/addtohomescreen.min.js');
  118. BxDolTemplate::getInstance()->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'cubiq-add-to-homescreen/style/|addtohomescreen.css');
  119. return "<script>addToHomescreen();</script>";
  120. }
  121. public function serviceAddPopupAlert()
  122. {
  123. return BxTemplFunctions::getInstance()->transBox('bx-popup-alert', BxDolTemplate::getInstance()->parseHtmlByName('popup_trans_alert_cnt.html', array()), true);
  124. }
  125. public function serviceAddPopupConfirm()
  126. {
  127. return BxTemplFunctions::getInstance()->transBox('bx-popup-confirm', BxDolTemplate::getInstance()->parseHtmlByName('popup_trans_confirm_cnt.html', array()), true);
  128. }
  129. public function serviceAddPopupPrompt()
  130. {
  131. $oTemplate = BxDolTemplate::getInstance();
  132. $sInputText = 'bx-popup-prompt-value';
  133. $aInputText = array(
  134. 'type' => 'text',
  135. 'name' => $sInputText,
  136. 'attrs' => array(
  137. 'id' => $sInputText,
  138. ),
  139. 'value' => '',
  140. 'caption' => ''
  141. );
  142. $oForm = new BxTemplFormView(array(), $oTemplate);
  143. return BxTemplFunctions::getInstance()->transBox('bx-popup-prompt', $oTemplate->parseHtmlByName('popup_trans_prompt_cnt.html', array(
  144. 'input' => $oForm->genRow($aInputText)
  145. )), true);
  146. }
  147. public function serviceAddPushInit($iProfileId = 0)
  148. {
  149. $iProfileId = !empty($iProfileId) ? $iProfileId : bx_get_logged_profile_id();
  150. if(empty($iProfileId))
  151. return '';
  152. $sAppId = getParam('sys_push_app_id');
  153. if(empty($sAppId))
  154. return '';
  155. $oTemplate = BxDolTemplate::getInstance();
  156. $sShortName = getParam('sys_push_short_name');
  157. $sSafariWebId = getParam('sys_push_safari_id');
  158. $oTemplate->addJs(array(
  159. 'https://cdn.onesignal.com/sdks/OneSignalSDK.js',
  160. 'BxDolPush.js',
  161. ));
  162. $oTemplate->addJsTranslation(array(
  163. '_sys_push_notification_request',
  164. '_sys_push_notification_request_yes',
  165. '_sys_push_notification_request_no'
  166. ));
  167. $sJsClass = 'BxDolPush';
  168. $sJsObject = 'oBxDolPush';
  169. $sContent = "var " . $sJsObject . " = new " . $sJsClass . "(" . json_encode(array(
  170. 'sObjName' => $sJsObject,
  171. 'sSiteName' => getParam('site_title'),
  172. 'iProfileId' => $iProfileId,
  173. 'sAppId' => $sAppId,
  174. 'sShortName' => $sShortName,
  175. 'sSafariWebId' => $sSafariWebId,
  176. 'sNotificationUrl' => BX_DOL_URL_ROOT,
  177. )) . ");";
  178. return $oTemplate->_wrapInTagJsCode($sContent);
  179. }
  180. }
  181. /** @} */