1
0

BxBaseModGeneralFormEntry.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  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 BaseGeneral Base classes for modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Create/edit entry form
  13. */
  14. class BxBaseModGeneralFormEntry extends BxTemplFormView
  15. {
  16. protected static $_isCssJsGeneralModuleAdded = false;
  17. protected $MODULE;
  18. protected $_oModule;
  19. protected $_aMetatagsFieldsWithKeywords = array();
  20. protected $_oMetatagsObject = null;
  21. protected $_oMetatagsContentId = 0;
  22. protected $_sGhostTemplate = 'form_ghost_template.html';
  23. protected $_aTrackFieldsChanges;
  24. public function __construct($aInfo, $oTemplate = false)
  25. {
  26. parent::__construct($aInfo, $oTemplate);
  27. $this->_oModule = BxDolModule::getInstance($this->MODULE);
  28. $this->_aTrackFieldsChanges = array();
  29. $CNF = &$this->_oModule->_oConfig->CNF;
  30. if (isset($CNF['FIELD_ADDED']) && isset($this->aInputs[$CNF['FIELD_ADDED']])) {
  31. $this->aInputs[$CNF['FIELD_ADDED']]['date_filter'] = BX_DATA_INT;
  32. $this->aInputs[$CNF['FIELD_ADDED']]['date_format'] = BX_FORMAT_DATE;
  33. }
  34. if (isset($CNF['FIELD_CHANGED']) && isset($this->aInputs[$CNF['FIELD_CHANGED']])) {
  35. $this->aInputs[$CNF['FIELD_CHANGED']]['date_filter'] = BX_DATA_INT;
  36. $this->aInputs[$CNF['FIELD_CHANGED']]['date_format'] = BX_FORMAT_DATE;
  37. }
  38. if (isset($CNF['FIELD_TEXT']) && isset($this->aInputs[$CNF['FIELD_TEXT']]) && isset($CNF['FIELD_TEXT_ID'])) {
  39. $this->aInputs[$CNF['FIELD_TEXT']]['attrs'] = array_merge (
  40. array ('id' => $CNF['FIELD_TEXT_ID']),
  41. is_array($this->aInputs[$CNF['FIELD_TEXT']]['attrs']) ? $this->aInputs[$CNF['FIELD_TEXT']]['attrs'] : array ()
  42. );
  43. }
  44. if (isset($CNF['FIELD_LOCATION_PREFIX']) && isset($this->aInputs[$CNF['FIELD_LOCATION_PREFIX']])) {
  45. $this->aInputs[$CNF['FIELD_LOCATION_PREFIX']]['manual_input'] = true;
  46. }
  47. if (isset($CNF['FIELD_PHOTO']) && isset($this->aInputs[$CNF['FIELD_PHOTO']])) {
  48. $this->aInputs[$CNF['FIELD_PHOTO']]['storage_object'] = $CNF['OBJECT_STORAGE'];
  49. $this->aInputs[$CNF['FIELD_PHOTO']]['uploaders'] = !empty($this->aInputs[$CNF['FIELD_PHOTO']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_PHOTO']]['value']) : $CNF['OBJECT_UPLOADERS'];
  50. $this->aInputs[$CNF['FIELD_PHOTO']]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW'];
  51. $this->aInputs[$CNF['FIELD_PHOTO']]['storage_private'] = 0;
  52. $this->aInputs[$CNF['FIELD_PHOTO']]['multiple'] = true;
  53. $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'] = 0;
  54. $this->aInputs[$CNF['FIELD_PHOTO']]['ghost_template'] = '';
  55. }
  56. $aPrivacyFields = $this->_getPrivacyFields();
  57. foreach($aPrivacyFields as $sField => $sObject)
  58. $this->_preparePrivacyField($sField, $sObject);
  59. }
  60. function getCode($bDynamicMode = false)
  61. {
  62. if(!$bDynamicMode && bx_is_dynamic_request())
  63. $bDynamicMode = true;
  64. $aPrivacyFields = $this->_getPrivacyFields();
  65. foreach($aPrivacyFields as $sField => $sObject)
  66. $this->_addCssJsPrivacyField($sField, $sObject, $bDynamicMode);
  67. return parent::getCode($bDynamicMode);
  68. }
  69. /**
  70. * Add field(s) which will be tracked during content update.
  71. */
  72. public function addTrackFields($mixedFields, $mixedContent)
  73. {
  74. if(empty($mixedContent) || empty($mixedFields))
  75. return;
  76. if(!is_array($mixedContent)) {
  77. $mixedContent = $this->_oModule->_oDb->getContentInfoById((int)$mixedContent);
  78. if(empty($mixedContent) || !is_array($mixedContent))
  79. return;
  80. }
  81. if(!is_array($mixedFields))
  82. $mixedFields = array($mixedFields);
  83. foreach($mixedFields as $sField) {
  84. if(!isset($mixedContent[$sField]))
  85. continue;
  86. $this->_aTrackFieldsChanges[$sField] = array(
  87. 'old' => $mixedContent[$sField],
  88. );
  89. }
  90. }
  91. /**
  92. * Checks if the field was changed.
  93. */
  94. public function isTrackFieldChanged($sField, $bReturnValues = false)
  95. {
  96. if(!isset($this->_aTrackFieldsChanges[$sField]) || $this->_aTrackFieldsChanges[$sField] === false)
  97. return false;
  98. return $bReturnValues ? $this->_aTrackFieldsChanges[$sField] : true;
  99. }
  100. function initChecker ($aValues = array (), $aSpecificValues = array())
  101. {
  102. $CNF = &$this->_oModule->_oConfig->CNF;
  103. if (!empty($CNF['FIELD_LOCATION_PREFIX']) && isset($this->aInputs[$CNF['FIELD_LOCATION_PREFIX']]) && isset($aValues[$CNF['FIELD_ID']]) && !empty($CNF['OBJECT_METATAGS']) && ($oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS'])) && $oMetatags->locationsIsEnabled())
  104. $this->aInputs[$CNF['FIELD_LOCATION_PREFIX']]['value'] = $oMetatags->locationsString($aValues[$CNF['FIELD_ID']], false);
  105. if (isset($CNF['FIELD_PHOTO']) && isset($this->aInputs[$CNF['FIELD_PHOTO']])) {
  106. $aContentInfo = false;
  107. if ($aValues && !empty($aValues['id'])) {
  108. $aContentInfo = $this->_oModule->_oDb->getContentInfoById ($aValues['id']);
  109. $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'] = $aValues['id'];
  110. }
  111. $this->aInputs[$CNF['FIELD_PHOTO']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplate, $this->_getPhotoGhostTmplVars($aContentInfo));
  112. }
  113. if (isset($CNF['FIELD_LABELS']) && isset($this->aInputs[$CNF['FIELD_LABELS']]) && !empty($aValues['id']) && ($oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS'])) && $oMetatags->keywordsIsEnabled() && ($aLabels = $oMetatags->keywordsGet($aValues['id']))) {
  114. $this->aInputs[$CNF['FIELD_LABELS']]['content_id'] = $aValues['id'];
  115. $this->aInputs[$CNF['FIELD_LABELS']]['meta_object'] = $CNF['OBJECT_METATAGS'];
  116. $this->aInputs[$CNF['FIELD_LABELS']]['value'] = array_intersect($aLabels, BxDolLabel::getInstance()->getLabels(array('type' => 'values')));
  117. }
  118. if (isset($CNF['FIELD_ANONYMOUS']) && isset($this->aInputs[$CNF['FIELD_ANONYMOUS']]) && isset($CNF['FIELD_AUTHOR']) && isset($aValues[$CNF['FIELD_AUTHOR']])) {
  119. $this->aInputs[$CNF['FIELD_ANONYMOUS']]['checked'] = $aValues[$CNF['FIELD_AUTHOR']] < 0;
  120. }
  121. $aPrivacyFields = $this->_getPrivacyFields();
  122. foreach($aPrivacyFields as $sField => $sObject)
  123. $this->_preloadPrivacyField($sField, $sObject, $aValues);
  124. parent::initChecker ($aValues, $aSpecificValues);
  125. }
  126. public function insert ($aValsToAdd = array(), $isIgnore = false)
  127. {
  128. $CNF = &$this->_oModule->_oConfig->CNF;
  129. if (isset($CNF['FIELD_AUTHOR']) && empty($aValsToAdd[$CNF['FIELD_AUTHOR']]))
  130. $aValsToAdd[$CNF['FIELD_AUTHOR']] = (isset($CNF['FIELD_ANONYMOUS']) && isset($this->aInputs[$CNF['FIELD_ANONYMOUS']]) && $this->getCleanValue($CNF['FIELD_ANONYMOUS']) ? -1 : 1) * bx_get_logged_profile_id ();
  131. if (isset($CNF['FIELD_ADDED']) && empty($aValsToAdd[$CNF['FIELD_ADDED']]) && empty($this->getCleanValue($CNF['FIELD_ADDED'])))
  132. $aValsToAdd[$CNF['FIELD_ADDED']] = time();
  133. if (isset($CNF['FIELD_CHANGED']) && empty($aValsToAdd[$CNF['FIELD_CHANGED']]) && empty($this->getCleanValue($CNF['FIELD_CHANGED'])))
  134. $aValsToAdd[$CNF['FIELD_CHANGED']] = time();
  135. if (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedSetThumb() && isset($CNF['FIELD_THUMB'])) {
  136. $aThumb = isset($_POST[$CNF['FIELD_THUMB']]) ? bx_process_input ($_POST[$CNF['FIELD_THUMB']], BX_DATA_INT) : false;
  137. $aValsToAdd[$CNF['FIELD_THUMB']] = 0;
  138. if (!empty($aThumb) && is_array($aThumb) && ($iFileThumb = array_pop($aThumb)))
  139. $aValsToAdd[$CNF['FIELD_THUMB']] = $iFileThumb;
  140. }
  141. if(!empty($CNF['OBJECT_METATAGS']))
  142. $this->_processMetas($aValsToAdd);
  143. if(isset($CNF['FIELD_STATUS']) && !empty($CNF['FIELDS_DELAYED_PROCESSING']) && !empty($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4'])) {
  144. $oTranscoder = BxDolTranscoder::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']);
  145. $aFields = $CNF['FIELDS_DELAYED_PROCESSING'];
  146. if(is_string($aFields))
  147. $aFields = explode(',', $aFields);
  148. foreach($aFields as $sField) {
  149. $mixedFieldValues = $this->getCleanValue($sField);
  150. if(empty($mixedFieldValues))
  151. continue;
  152. $oStorage = BxDolStorage::getObjectInstance($this->aInputs[$sField]['storage_object']);
  153. if(!$oStorage)
  154. continue;
  155. if(!is_array($mixedFieldValues))
  156. $mixedFieldValues = array($mixedFieldValues);
  157. foreach($mixedFieldValues as $mixedFieldValue) {
  158. $aInfo = $oStorage->getFile((int)$mixedFieldValue);
  159. if(empty($aInfo) || !is_array($aInfo))
  160. continue;
  161. if(strncmp($aInfo['mime_type'], 'video/', 6) != 0)
  162. continue;
  163. if($oTranscoder->isFileReady((int)$mixedFieldValue))
  164. continue;
  165. $aValsToAdd[$CNF['FIELD_STATUS']] = 'awaiting';
  166. break 2;
  167. }
  168. }
  169. }
  170. return parent::insert ($aValsToAdd, $isIgnore);
  171. }
  172. function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  173. {
  174. $CNF = &$this->_oModule->_oConfig->CNF;
  175. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  176. if(isset($CNF['FIELD_AUTHOR']) && isset($CNF['FIELD_ANONYMOUS']) && isset($this->aInputs[$CNF['FIELD_ANONYMOUS']]))
  177. $aValsToAdd[$CNF['FIELD_AUTHOR']] = ($this->getCleanValue($CNF['FIELD_ANONYMOUS']) ? -1 : 1) * abs($aContentInfo[$CNF['FIELD_AUTHOR']]);
  178. if(isset($CNF['FIELD_CHANGED']) && empty($aValsToAdd[$CNF['FIELD_CHANGED']]) && empty($this->getCleanValue($CNF['FIELD_CHANGED'])))
  179. $aValsToAdd[$CNF['FIELD_CHANGED']] = time();
  180. if(CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedSetThumb($iContentId) && isset($CNF['FIELD_THUMB'])) {
  181. $aThumb = bx_process_input (bx_get($CNF['FIELD_THUMB']), BX_DATA_INT);
  182. $aValsToAdd[$CNF['FIELD_THUMB']] = 0;
  183. if (!empty($aThumb) && is_array($aThumb) && ($iFileThumb = array_pop($aThumb)))
  184. $aValsToAdd[$CNF['FIELD_THUMB']] = $iFileThumb;
  185. }
  186. if(!empty($CNF['OBJECT_METATAGS']))
  187. $this->_processMetas($aValsToAdd);
  188. if(isset($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]) && $aContentInfo[$CNF['FIELD_STATUS']] == 'failed')
  189. $aValsToAdd[$CNF['FIELD_STATUS']] = 'active';
  190. $mixedResult = parent::update($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  191. if($mixedResult !== false)
  192. $this->_processTrackFields($iContentId);
  193. return $mixedResult;
  194. }
  195. protected function _associalFileWithContent($oStorage, $iFileId, $iProfileId, $iContentId, $sPictureField = '')
  196. {
  197. $oStorage->updateGhostsContentId ($iFileId, $iProfileId, $iContentId, $this->_isAdmin($iContentId));
  198. }
  199. protected function _getPhotoGhostTmplVars($aContentInfo = array())
  200. {
  201. $CNF = &$this->_oModule->_oConfig->CNF;
  202. return array (
  203. 'name' => $this->aInputs[$CNF['FIELD_PHOTO']]['name'],
  204. 'content_id' => (int)$this->aInputs[$CNF['FIELD_PHOTO']]['content_id'],
  205. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '',
  206. 'thumb_id' => isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) ? $aContentInfo[$CNF['FIELD_THUMB']] : 0,
  207. 'name_thumb' => isset($CNF['FIELD_THUMB']) ? $CNF['FIELD_THUMB'] : '',
  208. 'bx_if:set_thumb' => array (
  209. 'condition' => CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedSetThumb($this->aInputs[$CNF['FIELD_PHOTO']]['content_id']),
  210. 'content' => array (
  211. 'name_thumb' => isset($CNF['FIELD_THUMB']) ? $CNF['FIELD_THUMB'] : '',
  212. 'txt_pict_use_as_thumb' => _t(!empty($CNF['T']['txt_pict_use_as_thumb']) ? $CNF['T']['txt_pict_use_as_thumb'] : '_sys_txt_form_entry_input_picture_use_as_thumb')
  213. ),
  214. ),
  215. );
  216. }
  217. function delete ($iContentId, $aContentInfo = array())
  218. {
  219. $CNF = &$this->_oModule->_oConfig->CNF;
  220. // delete associated files
  221. if (!empty($CNF['OBJECT_STORAGE'])) {
  222. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  223. if ($oStorage)
  224. $oStorage->queueFilesForDeletionFromGhosts($aContentInfo[$CNF['FIELD_AUTHOR']], $iContentId);
  225. }
  226. // delete associated objects data
  227. if (!empty($CNF['OBJECT_VIEWS'])) {
  228. $o = BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $iContentId);
  229. if ($o) $o->onObjectDelete();
  230. }
  231. if (!empty($CNF['OBJECT_VOTES'])) {
  232. $o = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  233. if ($o) $o->onObjectDelete();
  234. }
  235. if (!empty($CNF['OBJECT_SCORES'])) {
  236. $o = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContentId);
  237. if ($o) $o->onObjectDelete();
  238. }
  239. if (!empty($CNF['OBJECT_COMMENTS'])) {
  240. $o = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  241. if ($o) $o->onObjectDelete();
  242. }
  243. if (!empty($CNF['OBJECT_METATAGS'])) {
  244. $o = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  245. if ($o) $o->onDeleteContent($iContentId);
  246. }
  247. // delete db record
  248. return parent::delete($iContentId);
  249. }
  250. protected function _isAdmin ($iContentId = 0)
  251. {
  252. return $this->_oModule->_isModerator();
  253. }
  254. public function processFiles ($sFieldFile, $iContentId = 0, $isAssociateWithContent = false)
  255. {
  256. $CNF = &$this->_oModule->_oConfig->CNF;
  257. if (!isset($this->aInputs[$sFieldFile]))
  258. return true;
  259. $mixedFileIds = $this->getCleanValue($sFieldFile);
  260. if(!$mixedFileIds)
  261. return true;
  262. $oStorage = BxDolStorage::getObjectInstance($this->aInputs[$sFieldFile]['storage_object']);
  263. if (!$oStorage)
  264. return false;
  265. $iProfileId = $this->getContentOwnerProfileId($iContentId);
  266. $aGhostFiles = $oStorage->getGhosts ($iProfileId, $isAssociateWithContent ? 0 : $iContentId, true, $this->_isAdmin($iContentId));
  267. if (!$aGhostFiles)
  268. return true;
  269. foreach ($aGhostFiles as $aFile) {
  270. if (is_array($mixedFileIds) && !in_array($aFile['id'], $mixedFileIds))
  271. continue;
  272. if ($aFile['private'])
  273. $oStorage->setFilePrivate ($aFile['id'], 1);
  274. if ($iContentId)
  275. $this->_associalFileWithContent($oStorage, $aFile['id'], $iProfileId, $iContentId, $sFieldFile);
  276. }
  277. return true;
  278. }
  279. function _deleteFile ($iFileId, $sStorage = '')
  280. {
  281. $CNF = &$this->_oModule->_oConfig->CNF;
  282. if (!$iFileId)
  283. return true;
  284. $sStorage = !empty($sStorage) ? $sStorage : $CNF['OBJECT_STORAGE'];
  285. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  286. if (!$oStorage)
  287. return false;
  288. if (!$oStorage->getFile($iFileId))
  289. return true;
  290. $iProfileId = bx_get_logged_profile_id();
  291. return $oStorage->deleteFile($iFileId, $iProfileId);
  292. }
  293. function addCssJs ()
  294. {
  295. if ((!isset($this->aParams['view_mode']) || !$this->aParams['view_mode']) && !self::$_isCssJsGeneralModuleAdded) {
  296. $this->_oModule->_oTemplate->addCss('forms.css');
  297. $this->_oModule->_oTemplate->addJs('modules/base/general/js/|forms.js');
  298. self::$_isCssJsGeneralModuleAdded = true;
  299. }
  300. return parent::addCssJs ();
  301. }
  302. function genViewRowValue(&$aInput)
  303. {
  304. $s = parent::genViewRowValue($aInput);
  305. if ($this->_oMetatagsObject && in_array($aInput['name'], $this->_aMetatagsFieldsWithKeywords) && $s)
  306. $s = $this->_oMetatagsObject->metaParse($this->_oMetatagsContentId, $s);
  307. return $s;
  308. }
  309. function setMetatagsKeywordsData($iId, $a, $o)
  310. {
  311. $this->_oMetatagsContentId = $iId;
  312. $this->_aMetatagsFieldsWithKeywords = $a;
  313. $this->_oMetatagsObject = $o;
  314. }
  315. function getContentOwnerProfileId ($iContentId)
  316. {
  317. return $this->_oModule->serviceGetContentOwnerProfileId($iContentId);
  318. }
  319. protected function _processTrackFields($mixedContent)
  320. {
  321. if(empty($mixedContent) || empty($this->_aTrackFieldsChanges))
  322. return;
  323. if(!is_array($mixedContent)) {
  324. $mixedContent = $this->_oModule->_oDb->getContentInfoById((int)$mixedContent);
  325. if(empty($mixedContent) || !is_array($mixedContent))
  326. return;
  327. }
  328. foreach($this->_aTrackFieldsChanges as $sField => $aValues)
  329. if($mixedContent[$sField] == $aValues['old'])
  330. $this->_aTrackFieldsChanges[$sField] = false;
  331. else
  332. $this->_aTrackFieldsChanges[$sField]['new'] = $mixedContent[$sField];
  333. }
  334. protected function _processMetas(&$aValsToAdd)
  335. {
  336. $CNF = &$this->_oModule->_oConfig->CNF;
  337. $sKey = 'FIELD_LABELS';
  338. if(isset($CNF[$sKey]) && isset($this->aInputs[$CNF[$sKey]]) && empty($aValsToAdd[$CNF[$sKey]])) {
  339. $aLabels = $this->getCleanValue($CNF[$sKey]);
  340. if(!empty($aLabels) && is_array($aLabels))
  341. $aValsToAdd[$CNF[$sKey]] = serialize($aLabels);
  342. }
  343. $sKey1 = 'FIELD_LOCATION';
  344. $sKey2 = 'FIELD_LOCATION_PREFIX';
  345. if(isset($CNF[$sKey1]) && isset($CNF[$sKey2]) && isset($this->aInputs[$CNF[$sKey1]]) && empty($aValsToAdd[$CNF[$sKey1]])) {
  346. $aLocation = BxDolMetatags::locationsRetrieveFromForm($CNF[$sKey2], $this);
  347. if(!empty($aLocation) && is_array($aLocation))
  348. $aValsToAdd[$CNF[$sKey1]] = serialize(BxDolMetatags::locationsParseComponents($aLocation));
  349. }
  350. }
  351. protected function _getPrivacyFields()
  352. {
  353. $CNF = &$this->_oModule->_oConfig->CNF;
  354. $aFields = array('FIELD_ALLOW_VIEW_TO' => 'OBJECT_PRIVACY_VIEW');
  355. if(isset($CNF['PRIVACY_FIELD_TO_OBJECT']) && is_array($CNF['PRIVACY_FIELD_TO_OBJECT']))
  356. $aFields = $CNF['PRIVACY_FIELD_TO_OBJECT'];
  357. return $aFields;
  358. }
  359. function _addCssJsPrivacyField($sField, $sObject, $bDynamicMode = false)
  360. {
  361. $CNF = &$this->_oModule->_oConfig->CNF;
  362. if(!isset($CNF[$sField]) || !isset($this->aInputs[$CNF[$sField]]) || !isset($CNF[$sObject]))
  363. return;
  364. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF[$sObject]);
  365. if(!$oPrivacy)
  366. return;
  367. $this->aInputs[$CNF[$sField]]['content'] = $oPrivacy->addCssJs($bDynamicMode) . $this->aInputs[$CNF[$sField]]['content'];
  368. }
  369. protected function _preparePrivacyField($sField, $sObject)
  370. {
  371. $CNF = &$this->_oModule->_oConfig->CNF;
  372. if(!isset($CNF[$sField]) || !isset($this->aInputs[$CNF[$sField]]) || !isset($CNF[$sObject]))
  373. return;
  374. $sPrivacy = $CNF[$sObject];
  375. $oPrivacy = BxDolPrivacy::getObjectInstance($sPrivacy);
  376. if(!$oPrivacy)
  377. return;
  378. $aSave = array('db' => array('pass' => 'Xss'));
  379. array_walk($this->aInputs[$CNF[$sField]], function ($a, $k, $aSave) {
  380. if (in_array($k, array('info', 'caption', 'value')))
  381. $aSave[0][$k] = $a;
  382. }, array(&$aSave));
  383. $aGroupChooser = $oPrivacy->getGroupChooser($sPrivacy);
  384. $this->aInputs[$CNF[$sField]] = array_merge($this->aInputs[$CNF[$sField]], $aGroupChooser, $aSave);
  385. }
  386. protected function _preloadPrivacyField($sField, $sObject, $aValues)
  387. {
  388. $CNF = &$this->_oModule->_oConfig->CNF;
  389. if(!isset($CNF[$sField]) || !isset($this->aInputs[$CNF[$sField]]) || !isset($CNF[$sObject]))
  390. return;
  391. $sPrivacy = $CNF[$sObject];
  392. $oPrivacy = BxDolPrivacy::getObjectInstance($sPrivacy);
  393. if(!$oPrivacy)
  394. return;
  395. $iContentId = !empty($aValues[$CNF['FIELD_ID']]) ? (int)$aValues[$CNF['FIELD_ID']] : 0;
  396. $iProfileId = !empty($iContentId) ? (int)$this->getContentOwnerProfileId($iContentId) : bx_get_logged_profile_id();
  397. $iGroupId = !empty($aValues[$CNF[$sField]]) ? $aValues[$CNF[$sField]] : 0;
  398. $sKey = $CNF[$sField];
  399. if(!isset($this->aInputs[$sKey]['content']))
  400. $this->aInputs[$sKey]['content'] = '';
  401. $this->aInputs[$sKey]['content'] .= $oPrivacy->initGroupChooser($sPrivacy, $iProfileId, array(
  402. 'content_id' => $iContentId,
  403. 'group_id' => $iGroupId,
  404. 'html_ids' => array(
  405. 'form' => $this->getId()
  406. )
  407. ));
  408. }
  409. }
  410. /** @} */