BxBaseModGeneralFormEntry.php 21 KB

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