1
0

BxBaseModGeneralFormEntry.php 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473
  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. protected $_iContentId;
  25. protected $_bAllowChangeUserForAdmins;
  26. public function __construct($aInfo, $oTemplate = false)
  27. {
  28. if (!isset($this->_bAllowChangeUserForAdmins))
  29. $this->_bAllowChangeUserForAdmins = true;
  30. parent::__construct($aInfo, $oTemplate);
  31. $this->_oModule = BxDolModule::getInstance($this->MODULE);
  32. $this->_aTrackFieldsChanges = array();
  33. $CNF = &$this->_oModule->_oConfig->CNF;
  34. if (isset($CNF['FIELD_ADDED']) && isset($this->aInputs[$CNF['FIELD_ADDED']])) {
  35. $this->aInputs[$CNF['FIELD_ADDED']]['date_filter'] = BX_DATA_INT;
  36. $this->aInputs[$CNF['FIELD_ADDED']]['date_format'] = BX_FORMAT_DATE;
  37. }
  38. if (isset($CNF['FIELD_CHANGED']) && isset($this->aInputs[$CNF['FIELD_CHANGED']])) {
  39. $this->aInputs[$CNF['FIELD_CHANGED']]['date_filter'] = BX_DATA_INT;
  40. $this->aInputs[$CNF['FIELD_CHANGED']]['date_format'] = BX_FORMAT_DATE;
  41. }
  42. if (isset($CNF['FIELD_TEXT']) && isset($this->aInputs[$CNF['FIELD_TEXT']]) && isset($CNF['FIELD_TEXT_ID'])) {
  43. $this->aInputs[$CNF['FIELD_TEXT']]['attrs'] = array_merge (
  44. array ('id' => $CNF['FIELD_TEXT_ID']),
  45. is_array($this->aInputs[$CNF['FIELD_TEXT']]['attrs']) ? $this->aInputs[$CNF['FIELD_TEXT']]['attrs'] : array ()
  46. );
  47. }
  48. if (isset($CNF['FIELD_LABELS']) && isset($this->aInputs[$CNF['FIELD_LABELS']]) && !empty($CNF['OBJECT_METATAGS']) && ($oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS'])) && $oMetatags->keywordsIsEnabled()) {
  49. $this->aInputs[$CNF['FIELD_LABELS']]['meta_object'] = $CNF['OBJECT_METATAGS'];
  50. }
  51. if (isset($CNF['FIELD_LOCATION_PREFIX']) && isset($this->aInputs[$CNF['FIELD_LOCATION_PREFIX']])) {
  52. $this->aInputs[$CNF['FIELD_LOCATION_PREFIX']]['manual_input'] = true;
  53. }
  54. // add ability to change author by admins in some apps
  55. if (!empty($CNF['FIELD_AUTHOR']) && ($this->_oModule->_isModerator() || $this->_oModule->_isAdministrator()) && $this->_isChangeUserForAdmins($this->aParams['display']))
  56. $this->aInputs = array_merge([
  57. $CNF['FIELD_AUTHOR'] => [
  58. 'type' => 'custom',
  59. 'name' => $CNF['FIELD_AUTHOR'],
  60. 'db' => ['pass' => 'Xss'],
  61. 'caption' => _t('_sys_form_input_caption_author')
  62. ],
  63. ], $this->aInputs);
  64. if (isset($CNF['FIELD_PHOTO']) && isset($this->aInputs[$CNF['FIELD_PHOTO']])) {
  65. $this->aInputs[$CNF['FIELD_PHOTO']]['storage_object'] = $CNF['OBJECT_STORAGE'];
  66. $this->aInputs[$CNF['FIELD_PHOTO']]['uploaders'] = !empty($this->aInputs[$CNF['FIELD_PHOTO']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_PHOTO']]['value']) : $CNF['OBJECT_UPLOADERS'];
  67. $this->aInputs[$CNF['FIELD_PHOTO']]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW'];
  68. $this->aInputs[$CNF['FIELD_PHOTO']]['storage_private'] = 0;
  69. $this->aInputs[$CNF['FIELD_PHOTO']]['multiple'] = true;
  70. $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'] = 0;
  71. $this->aInputs[$CNF['FIELD_PHOTO']]['ghost_template'] = '';
  72. }
  73. $aPrivacyFields = $this->_getPrivacyFields();
  74. foreach($aPrivacyFields as $sField => $sObject)
  75. $this->_preparePrivacyField($sField, $sObject);
  76. foreach($this->aInputs as $sKey => $aInput) {
  77. if ($aInput['type'] == 'nested_form'){
  78. $this->genGhostTemplateForInputNestedForm ($this->aInputs[$sKey]);
  79. }
  80. }
  81. }
  82. protected function _isModeAdd($sDisplay = '')
  83. {
  84. $CNF = &$this->_oModule->_oConfig->CNF;
  85. if(!$sDisplay && !empty($this->aParams['display']))
  86. $sDisplay = $this->aParams['display'];
  87. return isset($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']) && $sDisplay == $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'];
  88. }
  89. protected function _isModeEdit($sDisplay = '')
  90. {
  91. $CNF = &$this->_oModule->_oConfig->CNF;
  92. if(!$sDisplay && !empty($this->aParams['display']))
  93. $sDisplay = $this->aParams['display'];
  94. return isset($CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT']) && $sDisplay == $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'];
  95. }
  96. protected function _isChangeUserForAdmins($sDisplay)
  97. {
  98. if(!$this->_bAllowChangeUserForAdmins)
  99. return false;
  100. if($this->_isModeAdd($sDisplay) || $this->_isModeEdit($sDisplay))
  101. return true;
  102. return false;
  103. }
  104. function getCode($bDynamicMode = false)
  105. {
  106. $CNF = &$this->_oModule->_oConfig->CNF;
  107. if(!$bDynamicMode && bx_is_dynamic_request())
  108. $bDynamicMode = true;
  109. $this->_replaceMarkersInControls();
  110. $sResult = parent::getCode($bDynamicMode);
  111. if($this->isViewMode() && !$sResult)
  112. return $sResult;
  113. $aPrivacyFields = $this->_getPrivacyFields();
  114. foreach($aPrivacyFields as $sField => $sObject)
  115. $this->_addCssJsPrivacyField($sField, $sObject, $bDynamicMode);
  116. if(isset($CNF['PARAM_MULTICAT_ENABLED']) && $CNF['PARAM_MULTICAT_ENABLED'] === true) {
  117. $sInclude2 = '';
  118. $sInclude2 .= $this->_oModule->_oTemplate->addJs(['BxDolCategories.js'], $bDynamicMode);
  119. $sInclude2 .= $this->_oModule->_oTemplate->addCss(['categories.css'], $bDynamicMode);
  120. $sResult .= ($bDynamicMode ? $sInclude2 : '') . $this->_oModule->_oTemplate->getJsCode('categories');
  121. }
  122. if(($sKey = 'PARAM_POLL_ENABLED') && isset($CNF[$sKey]) && $CNF[$sKey] === true) {
  123. $iContentId = $this->_isModeEdit() ? $this->_iContentId : 0;
  124. $sResult .= $this->addCssJsPolls($bDynamicMode) . $this->_oModule->_oTemplate->getJsCode('poll', [
  125. 'js_object' => $this->_oModule->_oConfig->getJsObjectPoll($iContentId),
  126. 'iParentContentId' => $iContentId,
  127. 'sParentFormId' => $this->getId()
  128. ]);
  129. }
  130. return $sResult;
  131. }
  132. /**
  133. * Nested forms processing
  134. */
  135. function genInputNestedForm (&$aInput, $sInfo = '', $sError = '')
  136. {
  137. $sUniqId = genRndPwd (8, false);
  138. $aNestedForms = array();
  139. if (!$this->isSubmitted()){
  140. $aGhostTemplateParams = is_object($aInput['ghost_template']) ? $aInput['ghost_template']->aParams : $aInput['ghost_template']['params'];
  141. $aNestedValues = $this->_oModule->_oDb->getNestedBy(array(
  142. 'type' => 'content_id',
  143. 'id' => $this->_iContentId,
  144. 'key_name' => $aGhostTemplateParams['db']['key']
  145. ), $aGhostTemplateParams['db']['table']);
  146. foreach($aNestedValues as $aNestedValue) {
  147. $aNestedValuesRv = array();
  148. $oForm = $this->getNestedFormObject($aInput);
  149. foreach($aNestedValue as $aNestedKey => $aNestedItem) {
  150. if ($oForm->aParams['db']['key'] == $aNestedKey)
  151. $aNestedValuesRv[$aNestedKey . '[]'] = $aNestedItem;
  152. else
  153. $aNestedValuesRv[$aNestedKey] = $aNestedItem;
  154. }
  155. $oForm->initChecker($aNestedValuesRv);
  156. array_push(
  157. $aNestedForms,
  158. array(
  159. 'key_value' => $aNestedValuesRv[$oForm->aParams['db']['key'] . '[]'],
  160. 'key_name' => $aInput['name'],
  161. 'form_code' => $oForm->genRows(),
  162. 'js_instance_name' => 'oBxNestedForm_' . $sUniqId,
  163. 'nested_type' => $aInput['name'],
  164. )
  165. );
  166. }
  167. }
  168. else{
  169. $aInput['ghost_templates'] = $aInput['ghost_template'];
  170. $this->genGhostTemplateForInputNestedForm ($aInput);
  171. foreach($aInput['ghost_templates'] as $oForm) {
  172. if (isset($oForm->aInputs)){
  173. array_push(
  174. $aNestedForms,
  175. array(
  176. 'key_value' => $oForm->aInputs[$aInput['name']]['value'],
  177. 'key_name' => $aInput['name'],
  178. 'form_code' => $oForm->genRows(),
  179. 'js_instance_name' => 'oBxNestedForm_' . $sUniqId,
  180. 'nested_type' => $aInput['name'],
  181. )
  182. );
  183. }
  184. }
  185. }
  186. return $this->oTemplate->parseHtmlByName('form_field_nested_form.html', array(
  187. 'bx_repeat:items' => $aNestedForms,
  188. 'info' => $sInfo,
  189. 'error' => $sError,
  190. 'uniq_id' => $sUniqId,
  191. 'js_instance_name' => 'oBxNestedForm_' . $sUniqId,
  192. 'options' => json_encode(array(
  193. 'uniq_id' => $sUniqId,
  194. 'js_instance_name' => 'oBxNestedForm_' . $sUniqId,
  195. 'template_ghost' => $this->genGhostTemplate($aInput),
  196. 'form_name' => $aInput['value'],
  197. 'action_uri' => $this->_oModule->_oConfig->getBaseUri(),
  198. 'nested_type' => $aInput['name'],
  199. )),
  200. ));
  201. }
  202. function genNestedForm (&$aInput)
  203. {
  204. $sResult = '';
  205. $aGhostTemplateParams = is_object($aInput['ghost_template']) ? $aInput['ghost_template']->aParams : $aInput['ghost_template']['params'];
  206. $aNestedValues = $this->_oModule->_oDb->getNestedBy([
  207. 'type' => 'content_id',
  208. 'id' => $this->_iContentId,
  209. 'key_name' => $aGhostTemplateParams['db']['key']
  210. ], $aGhostTemplateParams['db']['table']);
  211. foreach($aNestedValues as $aNestedValue) {
  212. $oForm = $this->getNestedFormObject($aInput, true);
  213. $aNestedValuesRv = [];
  214. foreach($aNestedValue as $aNestedKey => $aNestedItem) {
  215. if ($oForm->aParams['db']['key'] == $aNestedKey)
  216. $aNestedValuesRv[$aNestedKey . '[]'] = $aNestedItem;
  217. else
  218. $aNestedValuesRv[$aNestedKey] = $aNestedItem;
  219. }
  220. $oForm->initChecker($aNestedValuesRv);
  221. $sValue = '';
  222. if($aInput['rateable']) {
  223. $iId = BxDolFormQuery::getFormField($this->id, $aInput['name'], $this->_iContentId, $aNestedValuesRv[$oForm->aParams['db']['key'] . '[]']);
  224. $sVoteElement = '';
  225. $sVoteCounter = '';
  226. if(($oVote = BxDolVote::getObjectInstance($aInput['rateable'], $iId)) !== null) {
  227. $sVoteElement = $oVote->getElementInline(['show_counter_empty' => true, 'show_counter' => false, 'show_counter_style' => 'simple', 'dynamic_mode' => $this->_bDynamicMode]);
  228. $sVoteCounter = $oVote->getCounter(['show_counter_empty' => true, 'show_counter' => true, 'show_counter_style' => 'simple', 'dynamic_mode' => $this->_bDynamicMode]);
  229. }
  230. $sValue = $this->oTemplate->parseHtmlByName('form_view_rateable_row.html', [
  231. 'value' => $oForm->getCode(),
  232. 'rate_btn' => $sVoteElement,
  233. 'rate' => $sVoteCounter,
  234. ]);
  235. }
  236. else
  237. $sValue = $oForm->getCode();
  238. $sResult .= $this->oTemplate->parseHtmlByName('form_view_nested_row.html', [
  239. 'value' => $sValue
  240. ]);
  241. }
  242. if(!$sResult)
  243. return '';
  244. $aTmplVarsIcon = [];
  245. if(!empty($aInput['icon'])) {
  246. list($sIcon, $sIconUrl, $sIconA, $sIconHtml) = BxTemplFunctions::getInstanceWithTemplate($this->oTemplate)->getIcon($aInput['icon']);
  247. $aTmplVarsIcon = [
  248. 'bx_if:icon' => [
  249. 'condition' => (bool)$sIcon,
  250. 'content' => ['icon' => $sIcon],
  251. ],
  252. 'bx_if:icon-html' => [
  253. 'condition' => (bool)$sIconHtml,
  254. 'content' => ['icon' => $sIconHtml],
  255. ],
  256. 'bx_if:image_inline' => [
  257. 'condition' => false,
  258. 'content' => ['image' => ''],
  259. ]
  260. ];
  261. }
  262. return $this->oTemplate->parseHtmlByName('form_view_row.html', [
  263. 'type' => $aInput['type'],
  264. 'class' => '',
  265. 'bx_if:show_icon' => [
  266. 'condition' => !empty($aTmplVarsIcon),
  267. 'content' => $aTmplVarsIcon
  268. ],
  269. 'caption' => isset($aInput['caption']) ? bx_process_output($aInput['caption']) : '',
  270. 'class_value' => '',
  271. 'value' => $sResult
  272. ]);
  273. }
  274. protected function genGhostTemplateForInputNestedForm (&$aInput)
  275. {
  276. $oForm = $this->getNestedFormObject($aInput);
  277. $aInput['ghost_template'] = array (
  278. 'params' => array(
  279. 'nested_form_template' => 'form_field_nested_form_wrapper.html',
  280. 'db' => array(
  281. 'table' => $oForm->aParams['db']['table'],
  282. 'key' => $oForm->aParams['db']['key'],
  283. 'submit_name' => $oForm->aParams['db']['key'],
  284. ),
  285. ),
  286. 'inputs' => $oForm->aInputs
  287. );
  288. }
  289. function getNestedFormObject (&$aInput, $bViewMode = false)
  290. {
  291. $oForm = BxDolForm::getObjectInstance($aInput['value'], $aInput['value'] . ($bViewMode ? '_view' : ''));
  292. foreach($oForm->aInputs as $sKey => $aInput2) {
  293. $sName = $oForm->aInputs[$sKey]['name'];
  294. if (strpos($sName,'[]') === false)
  295. $oForm->aInputs[$sKey]['name'] = $sName . '[]';
  296. }
  297. return $oForm;
  298. }
  299. /**
  300. * Add field(s) which will be tracked during content update.
  301. */
  302. public function addTrackFields($mixedFields, $mixedContent)
  303. {
  304. if(empty($mixedContent) || empty($mixedFields))
  305. return;
  306. if(!is_array($mixedContent)) {
  307. $mixedContent = $this->_oModule->_oDb->getContentInfoById((int)$mixedContent);
  308. if(empty($mixedContent) || !is_array($mixedContent))
  309. return;
  310. }
  311. if(!is_array($mixedFields))
  312. $mixedFields = array($mixedFields);
  313. foreach($mixedFields as $sField) {
  314. if(!isset($mixedContent[$sField]))
  315. continue;
  316. $this->_aTrackFieldsChanges[$sField] = array(
  317. 'old' => $mixedContent[$sField],
  318. );
  319. }
  320. }
  321. /**
  322. * Checks if the field was changed.
  323. */
  324. public function isTrackFieldChanged($sField, $bReturnValues = false)
  325. {
  326. if(!isset($this->_aTrackFieldsChanges[$sField]) || $this->_aTrackFieldsChanges[$sField]['result'] === false)
  327. return false;
  328. return $bReturnValues ? $this->_aTrackFieldsChanges[$sField] : true;
  329. }
  330. function initChecker ($aValues = array (), $aSpecificValues = array())
  331. {
  332. $CNF = &$this->_oModule->_oConfig->CNF;
  333. $bValues = $aValues && !empty($aValues['id']);
  334. $this->_iContentId = isset($aValues['id']) ? $aValues['id'] : false;
  335. if (!empty($CNF['URI_VIEW_ENTRY']) && $this->_iContentId)
  336. $this->addMarkers([
  337. 'edit_cancel_url' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $this->_iContentId))
  338. ]);
  339. 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())
  340. $this->aInputs[$CNF['FIELD_LOCATION_PREFIX']]['value'] = $oMetatags->locationsString($aValues[$CNF['FIELD_ID']], false);
  341. if (isset($CNF['FIELD_PHOTO']) && isset($this->aInputs[$CNF['FIELD_PHOTO']])) {
  342. $aContentInfo = false;
  343. if ($aValues && !empty($aValues['id'])) {
  344. $aContentInfo = $this->_oModule->_oDb->getContentInfoById ($aValues['id']);
  345. $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'] = $aValues['id'];
  346. }
  347. $this->aInputs[$CNF['FIELD_PHOTO']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplate, $this->_getPhotoGhostTmplVars($aContentInfo));
  348. }
  349. if (isset($CNF['FIELD_POLL']) && isset($this->aInputs[$CNF['FIELD_POLL']])) {
  350. if ($bValues)
  351. $this->aInputs[$CNF['FIELD_POLL']]['content_id'] = $aValues['id'];
  352. }
  353. 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'])) {
  354. $this->aInputs[$CNF['FIELD_LABELS']]['content_id'] = $aValues['id'];
  355. if(($aLabels = $oMetatags->keywordsGet($aValues['id'])))
  356. $this->aInputs[$CNF['FIELD_LABELS']]['value'] = array_intersect($aLabels, BxDolLabel::getInstance()->getLabels(array('type' => 'values')));
  357. }
  358. if (isset($CNF['FIELD_ANONYMOUS'], $this->aInputs[$CNF['FIELD_ANONYMOUS']]) && isset($CNF['FIELD_AUTHOR'], $aValues[$CNF['FIELD_AUTHOR']])) {
  359. $this->aInputs[$CNF['FIELD_ANONYMOUS']]['checked'] = $aValues[$CNF['FIELD_AUTHOR']] < 0;
  360. }
  361. if (isset($CNF['FIELD_MULTICAT']) && isset($this->aInputs[$CNF['FIELD_MULTICAT']]) && $CNF['PARAM_MULTICAT_ENABLED']) {
  362. if ($bValues)
  363. $this->aInputs[$CNF['FIELD_MULTICAT']]['content_id'] = $aValues['id'];
  364. }
  365. $aPrivacyFields = $this->_getPrivacyFields();
  366. foreach($aPrivacyFields as $sField => $sObject)
  367. $this->_preloadPrivacyField($sField, $sObject, $aValues);
  368. if(isset($CNF['FIELD_AUTHOR'], $this->aInputs[$CNF['FIELD_AUTHOR']])) {
  369. if (isset($aValues[$CNF['FIELD_AUTHOR']]) && $aValues[$CNF['FIELD_AUTHOR']])
  370. $aValues[$CNF['FIELD_AUTHOR']] = abs($aValues[$CNF['FIELD_AUTHOR']]);
  371. else
  372. $aValues[$CNF['FIELD_AUTHOR']] = bx_get_logged_profile_id();
  373. }
  374. parent::initChecker ($aValues, $aSpecificValues);
  375. $this->_processContextBeforeAdd();
  376. foreach($aPrivacyFields as $sField => $sObject)
  377. $this->_validatePrivacyField($sField, $sObject, $aValues);
  378. }
  379. public function insert ($aValsToAdd = array(), $isIgnore = false)
  380. {
  381. $CNF = &$this->_oModule->_oConfig->CNF;
  382. $iAuthor = -1;
  383. if(isset($CNF['FIELD_AUTHOR'])) {
  384. $sFa = $CNF['FIELD_AUTHOR'];
  385. $iAnonymous = isset($CNF['FIELD_ANONYMOUS'], $this->aInputs[$CNF['FIELD_ANONYMOUS']]) && $this->getCleanValue($CNF['FIELD_ANONYMOUS']) ? -1 : 1;
  386. if(empty($aValsToAdd[$sFa])) {
  387. if(!isset($this->aInputs[$sFa]) || empty($this->getCleanValue($sFa)))
  388. $iAuthor = bx_get_logged_profile_id();
  389. else
  390. $iAuthor = $this->getCleanValue($sFa);
  391. $aValsToAdd[$sFa] = $iAnonymous * $iAuthor;
  392. }
  393. else {
  394. $iAuthor = $aValsToAdd[$sFa];
  395. $aValsToAdd[$sFa] *= $iAnonymous;
  396. }
  397. }
  398. if (isset($CNF['FIELD_ADDED']) && empty($aValsToAdd[$CNF['FIELD_ADDED']]) && empty($this->getCleanValue($CNF['FIELD_ADDED'])))
  399. $aValsToAdd[$CNF['FIELD_ADDED']] = time();
  400. if (isset($CNF['FIELD_CHANGED']) && empty($aValsToAdd[$CNF['FIELD_CHANGED']]) && empty($this->getCleanValue($CNF['FIELD_CHANGED'])))
  401. $aValsToAdd[$CNF['FIELD_CHANGED']] = time();
  402. if (($sKey = 'FIELD_THUMB') && isset($CNF[$sKey]) && ($aThumb = bx_get($CNF[$sKey])) !== false && $this->_oModule->checkAllowedSetThumb() === CHECK_ACTION_RESULT_ALLOWED) {
  403. $aThumb = bx_process_input ($aThumb, BX_DATA_INT);
  404. $aValsToAdd[$CNF[$sKey]] = 0;
  405. if (!empty($aThumb)){
  406. if(is_array($aThumb) && ($iFileThumb = array_pop($aThumb)))
  407. $aValsToAdd[$CNF[$sKey]] = $iFileThumb;
  408. else
  409. $aValsToAdd[$CNF[$sKey]] = $aThumb;
  410. }
  411. }
  412. if(!empty($CNF['OBJECT_METATAGS']))
  413. $this->_processMetas($aValsToAdd);
  414. if(isset($CNF['FIELD_STATUS']) && !empty($CNF['FIELDS_DELAYED_PROCESSING']) && !empty($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4'])) {
  415. $oTranscoder = BxDolTranscoder::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']);
  416. $aFields = $CNF['FIELDS_DELAYED_PROCESSING'];
  417. if(is_string($aFields))
  418. $aFields = explode(',', $aFields);
  419. foreach($aFields as $sField) {
  420. $mixedFieldValues = $this->getCleanValue($sField);
  421. if(empty($mixedFieldValues))
  422. continue;
  423. $oStorage = BxDolStorage::getObjectInstance($this->aInputs[$sField]['storage_object']);
  424. if(!$oStorage)
  425. continue;
  426. if(!is_array($mixedFieldValues))
  427. $mixedFieldValues = array($mixedFieldValues);
  428. foreach($mixedFieldValues as $mixedFieldValue) {
  429. $aInfo = $oStorage->getFile((int)$mixedFieldValue);
  430. if(empty($aInfo) || !is_array($aInfo))
  431. continue;
  432. if(strncmp($aInfo['mime_type'], 'video/', 6) != 0)
  433. continue;
  434. if($oTranscoder->isFileReady((int)$mixedFieldValue))
  435. continue;
  436. $aValsToAdd[$CNF['FIELD_STATUS']] = 'awaiting';
  437. break 2;
  438. }
  439. }
  440. }
  441. if(isset($CNF['FIELD_STATUS_ADMIN']) && empty($aValsToAdd[$CNF['FIELD_STATUS_ADMIN']]) && !$this->_oModule->_isModerator() && !$this->_oModule->_oConfig->isAutoApproveEnabled())
  442. $aValsToAdd[$CNF['FIELD_STATUS_ADMIN']] = BX_BASE_MOD_GENERAL_STATUS_PENDING;
  443. $bMulticatEnabled = $this->_isMulticatEnabled();
  444. if ($bMulticatEnabled)
  445. $this->processMulticatBefore($CNF['FIELD_MULTICAT'], $aValsToAdd);
  446. $iContentId = parent::insert ($aValsToAdd, $isIgnore);
  447. if(empty($iContentId))
  448. return $iContentId;
  449. foreach($this->aInputs as $aInput) {
  450. if ($aInput['type'] == 'nested_form') {
  451. if (is_array($aInput['ghost_template']) && !isset($aInput['ghost_template']['inputs'])) {
  452. foreach ($aInput['ghost_template'] as $oFormNested) {
  453. $iNestedContentId = $oFormNested->insert(array('content_id' => $iContentId));
  454. if ($aInput['rateable']) {
  455. BxDolFormQuery::addFormField($this->id, $aInput['name'], $iContentId, $iAuthor, $this->_oModule->getName(), $iNestedContentId);
  456. }
  457. }
  458. }
  459. }
  460. }
  461. if($this->_bIsApi && ($sKeyF = 'FIELD_ALLOW_VIEW_TO') && isset($CNF[$sKeyF]) && ($mixedAllowViewTo = $this->getCleanValue($CNF[$sKeyF])) !== false) {
  462. $aAllowViewToItems = [];
  463. if(($mixedAllowViewToItems = $this->getCleanValue($CNF[$sKeyF] . '_items')) !== false)
  464. $aAllowViewToItems = explode(',', $mixedAllowViewToItems);
  465. if(($sKeyO = 'OBJECT_PRIVACY_VIEW') && isset($CNF[$sKeyO]) && ($sObject = $CNF[$sKeyO]) && ($oPrivacy = BxDolPrivacy::getObjectInstance($sObject)) !== false)
  466. $oPrivacy->addGroupCustom([
  467. 'profile_id' => $iAuthor,
  468. 'content_id' => 0,
  469. 'object' => $sObject,
  470. 'group_id' => (int)$mixedAllowViewTo
  471. ], $aAllowViewToItems);
  472. }
  473. if($bMulticatEnabled)
  474. $this->processMulticatAfter($CNF['FIELD_MULTICAT'], $iContentId);
  475. foreach($this->aInputs as $aInput)
  476. if(isset($aInput['rateable']) && $aInput['rateable'] && $aInput['type'] != 'nested_form')
  477. BxDolFormQuery::addFormField($this->id, $aInput['name'], $iContentId, $iAuthor, $this->_oModule->getName());
  478. if(($iContextNid = $this->getCleanValue('context_nid')) !== false)
  479. $this->_processContextAfterAdd($iContentId, $iContextNid, (int)$this->getCleanValue('context_usage'));
  480. // invalidate menu profile stats cache
  481. if (isset($aContentInfo[$CNF['FIELD_AUTHOR']]));
  482. bx_content_cache_del("menu_sys_profile_stats_p" . $iAuthor);
  483. return $iContentId;
  484. }
  485. function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  486. {
  487. $CNF = &$this->_oModule->_oConfig->CNF;
  488. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  489. $iAuthor = -1;
  490. if(isset($CNF['FIELD_AUTHOR'])) {
  491. $sFa = $CNF['FIELD_AUTHOR'];
  492. if(!empty($aValsToAdd[$sFa]))
  493. $iAuthor = $aValsToAdd[$sFa];
  494. else if(isset($this->aInputs[$sFa]) && !empty($this->getCleanValue($sFa)))
  495. $iAuthor = $this->getCleanValue($sFa);
  496. else if(!empty($aContentInfo[$sFa]))
  497. $iAuthor = $aContentInfo[$sFa];
  498. else
  499. $iAuthor = bx_get_logged_profile_id();
  500. $iAuthor = abs($iAuthor);
  501. $iAnonymous = isset($CNF['FIELD_ANONYMOUS'], $this->aInputs[$CNF['FIELD_ANONYMOUS']]) && $this->getCleanValue($CNF['FIELD_ANONYMOUS']) ? -1 : 1;
  502. $aValsToAdd[$sFa] = $iAnonymous * $iAuthor;
  503. }
  504. if(isset($CNF['FIELD_CHANGED']) && empty($aValsToAdd[$CNF['FIELD_CHANGED']]) && empty($this->getCleanValue($CNF['FIELD_CHANGED'])))
  505. $aValsToAdd[$CNF['FIELD_CHANGED']] = time();
  506. if(($sKey = 'FIELD_THUMB') && isset($CNF[$sKey]) && ($aThumb = bx_get($CNF[$sKey])) !== false && $this->_oModule->checkAllowedSetThumb($iContentId) === CHECK_ACTION_RESULT_ALLOWED) {
  507. $aThumb = bx_process_input($aThumb, BX_DATA_INT);
  508. $aValsToAdd[$CNF[$sKey]] = 0;
  509. if(!empty($aThumb)) {
  510. if(is_array($aThumb) && ($iFileThumb = array_pop($aThumb)))
  511. $aValsToAdd[$CNF[$sKey]] = $iFileThumb;
  512. else
  513. $aValsToAdd[$CNF[$sKey]] = $aThumb;
  514. }
  515. }
  516. if(!empty($CNF['OBJECT_METATAGS']))
  517. $this->_processMetas($aValsToAdd);
  518. if(isset($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]) && $aContentInfo[$CNF['FIELD_STATUS']] == 'failed')
  519. $aValsToAdd[$CNF['FIELD_STATUS']] = 'active';
  520. $bMulticatEnabled = $this->_isMulticatEnabled();
  521. if ($bMulticatEnabled)
  522. $this->processMulticatBefore($CNF['FIELD_MULTICAT'], $aValsToAdd);
  523. $mixedResult = parent::update($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  524. foreach($this->aInputs as $aInput) {
  525. if ($aInput['type'] == 'nested_form'){
  526. if (is_array($aInput['ghost_template']) && !isset($aInput['ghost_template']['inputs'])) {
  527. foreach ($aInput['ghost_template'] as $oFormNested) {
  528. $aSpecificValues = $oFormNested->getSpecificValues();
  529. $iNestedContentId = $oFormNested->getSubmittedValue($aInput['name'], BX_DOL_FORM_METHOD_SPECIFIC, $aSpecificValues);
  530. if (empty($iNestedContentId)){
  531. $iNestedContentId = $oFormNested->insert(array('content_id' => $iContentId));
  532. if ($aInput['rateable']){
  533. BxDolFormQuery::addFormField($this->id, $aInput['name'], $iContentId, $iAuthor, $this->_oModule->getName(), $iNestedContentId);
  534. }
  535. }
  536. else{
  537. $oFormNested->update($iNestedContentId, array('content_id' => $iContentId));
  538. }
  539. }
  540. }
  541. }
  542. }
  543. if ($bMulticatEnabled)
  544. $this->processMulticatAfter($CNF['FIELD_MULTICAT'], $iContentId);
  545. foreach($this->aInputs as $aInput) {
  546. if (isset($aInput['rateable']) && $aInput['rateable'] && $aInput['type'] != 'nested_form'){
  547. BxDolFormQuery::addFormField($this->id, $aInput['name'], $iContentId, $iAuthor, $this->_oModule->getName());
  548. }
  549. }
  550. if($mixedResult !== false) {
  551. $this->_processTrackFields($iContentId);
  552. if($this->_bIsApi && ($sKeyF = 'FIELD_ALLOW_VIEW_TO') && isset($CNF[$sKeyF]) && ($mixedAllowViewTo = $this->getCleanValue($CNF[$sKeyF])) !== false) {
  553. $aAllowViewToItems = [];
  554. if(($mixedAllowViewToItems = $this->getCleanValue($CNF[$sKeyF] . '_items')) !== false)
  555. $aAllowViewToItems = explode(',', $mixedAllowViewToItems);
  556. if(($sKeyO = 'OBJECT_PRIVACY_VIEW') && isset($CNF[$sKeyO]) && ($sObject = $CNF[$sKeyO]) && ($oPrivacy = BxDolPrivacy::getObjectInstance($sObject)) !== false) {
  557. $oPrivacy->editGroupCustom([
  558. 'profile_id' => $iAuthor,
  559. 'content_id' => $iContentId,
  560. 'object' => $sObject,
  561. 'group_id' => (int)$mixedAllowViewTo
  562. ], $aAllowViewToItems);
  563. }
  564. }
  565. }
  566. return $mixedResult;
  567. }
  568. public function getCleanValue($sName)
  569. {
  570. $CNF = &$this->_oModule->_oConfig->CNF;
  571. $mixedValue = parent::getCleanValue($sName);
  572. if($this->_bIsApi && !empty($mixedValue)) {
  573. if(($sF = 'FIELD_POLL') && isset($CNF[$sF]) && strcmp($sName, $CNF[$sF]) == 0)
  574. $mixedValue = explode(',', $mixedValue);
  575. }
  576. return $mixedValue;
  577. }
  578. function getHtmlEditorQueryParams($aInput)
  579. {
  580. $aQueryParams = array_merge(parent::getHtmlEditorQueryParams($aInput), $this->getMentionsQueryParams($aInput), [
  581. 'fi' => ''
  582. ]);
  583. /**
  584. * @hooks
  585. * @hookdef hook-system-editor_query_params 'system', 'editor_query_params' - hook to override http(s) request's query params, which is used in HTML editor
  586. * - $unit_name - equals `system`
  587. * - $action - equals `editor_query_params`
  588. * - $object_id - not used
  589. * - $sender_id - not used
  590. * - $extra_params - array of additional params with the following array keys:
  591. * - `form` - [object] an instance of form, @see BxDolForm
  592. * - `override_result` - [array] by ref, query string params, can be overridden in hook processing
  593. * @hook @ref hook-system-editor_query_params
  594. */
  595. bx_alert('system', 'editor_query_params', 0, 0, [
  596. 'form' => $this,
  597. 'override_result' => &$aQueryParams
  598. ]);
  599. return $aQueryParams;
  600. }
  601. function getMentionsQueryParams($aInput)
  602. {
  603. $CNF = &$this->_oModule->_oConfig->CNF;
  604. $aParams = array_merge(parent::getMentionsQueryParams($aInput), [
  605. 'ct' => 'content',
  606. 'cm' => $this->MODULE ?: '',
  607. 'ci' => $this->_iContentId ?: 0,
  608. 'cp' => ''
  609. ]);
  610. if(($sF = $CNF['FIELD_ALLOW_VIEW_TO'] ?? false) && ($aF = $this->aInputs[$sF] ?? false) || ($sF = $CNF['FIELD_OBJECT_PRIVACY_VIEW'] ?? false) && ($aF = $this->aInputs[$sF] ?? false))
  611. $aParams['cp'] = $aF['value'];
  612. return $aParams;
  613. }
  614. protected function _associalFileWithContent($oStorage, $iFileId, $iProfileId, $iContentId, $sPictureField = '')
  615. {
  616. $oStorage->updateGhostsContentId ($iFileId, $iProfileId, $iContentId, $this->_isAdmin($iContentId));
  617. }
  618. protected function _getPhotoGhostTmplVars($aContentInfo = array())
  619. {
  620. $CNF = &$this->_oModule->_oConfig->CNF;
  621. return array (
  622. 'name' => $this->aInputs[$CNF['FIELD_PHOTO']]['name'],
  623. 'content_id' => (int)$this->aInputs[$CNF['FIELD_PHOTO']]['content_id'],
  624. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '',
  625. 'thumb_id' => isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) ? $aContentInfo[$CNF['FIELD_THUMB']] : 0,
  626. 'name_thumb' => isset($CNF['FIELD_THUMB']) ? $CNF['FIELD_THUMB'] : '',
  627. 'bx_if:set_thumb' => array (
  628. 'condition' => CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedSetThumb($this->aInputs[$CNF['FIELD_PHOTO']]['content_id']),
  629. 'content' => array (
  630. 'name_thumb' => isset($CNF['FIELD_THUMB']) ? $CNF['FIELD_THUMB'] : '',
  631. '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')
  632. ),
  633. ),
  634. );
  635. }
  636. function delete ($iContentId, $aContentInfo = array())
  637. {
  638. $CNF = &$this->_oModule->_oConfig->CNF;
  639. // delete associated files
  640. $a = array('OBJECT_STORAGE', 'OBJECT_STORAGE_FILES', 'OBJECT_STORAGE_PHOTOS', 'OBJECT_STORAGE_VIDEOS', 'OBJECT_STORAGE_SOUNDS');
  641. foreach ($a as $k) {
  642. if (!empty($CNF[$k])) {
  643. $oStorage = BxDolStorage::getObjectInstance($CNF[$k]);
  644. if ($oStorage)
  645. $oStorage->queueFilesForDeletionFromGhosts($aContentInfo[$CNF['FIELD_AUTHOR']], $iContentId);
  646. }
  647. }
  648. // delete associated objects data
  649. if (!empty($CNF['OBJECT_VIEWS'])) {
  650. $o = BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $iContentId);
  651. if ($o) $o->onObjectDelete();
  652. }
  653. if (!empty($CNF['OBJECT_VOTES'])) {
  654. $o = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  655. if ($o) $o->onObjectDelete();
  656. }
  657. if (!empty($CNF['OBJECT_SCORES'])) {
  658. $o = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContentId);
  659. if ($o) $o->onObjectDelete();
  660. }
  661. if (!empty($CNF['OBJECT_COMMENTS'])) {
  662. $o = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  663. if ($o) $o->onObjectDelete();
  664. }
  665. if (!empty($CNF['OBJECT_REPORTS'])) {
  666. $o = BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $iContentId);
  667. if ($o) $o->onObjectDelete();
  668. }
  669. if (!empty($CNF['OBJECT_METATAGS'])) {
  670. $o = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  671. if ($o) $o->onDeleteContent($iContentId);
  672. }
  673. // delete SEO links
  674. BxDolPage::deleteSeoLink ($this->_oModule->getName(), $this->_oModule->getName(), $iContentId);
  675. // delete db record
  676. BxDolFormQuery::removeFormField($this->id, $iContentId);
  677. // invalidate menu profile stats cache
  678. if (isset($aContentInfo[$CNF['FIELD_AUTHOR']]));
  679. bx_content_cache_del("menu_sys_profile_stats_p" . $aContentInfo[$CNF['FIELD_AUTHOR']]);
  680. return parent::delete($iContentId);
  681. }
  682. protected function _isAdmin ($iContentId = 0)
  683. {
  684. return $this->_oModule->_isModerator();
  685. }
  686. public function processFiles ($sFieldFile, $iContentId = 0, $isAssociateWithContent = false)
  687. {
  688. if(!isset($this->aInputs[$sFieldFile]))
  689. return true;
  690. $mixedFileIds = $this->getCleanValue($sFieldFile);
  691. if(!$mixedFileIds)
  692. return true;
  693. $oStorage = BxDolStorage::getObjectInstance($this->aInputs[$sFieldFile]['storage_object']);
  694. if (!$oStorage)
  695. return false;
  696. $iProfileId = $this->getContentOwnerProfileId($iContentId);
  697. $aGhostFiles = $oStorage->getGhosts ($iProfileId, $isAssociateWithContent ? 0 : $iContentId, true, $this->_isAdmin($iContentId));
  698. if(!empty($aGhostFiles) && is_array($aGhostFiles))
  699. foreach($aGhostFiles as $aFile) {
  700. if(is_array($mixedFileIds) && !in_array($aFile['id'], $mixedFileIds))
  701. continue;
  702. if($aFile['private'])
  703. $oStorage->setFilePrivate ($aFile['id'], 1);
  704. if($iContentId)
  705. $this->_associalFileWithContent($oStorage, $aFile['id'], $iProfileId, $iContentId, $sFieldFile);
  706. }
  707. if($this->_bAllowChangeUserForAdmins && ($this->_oModule->_isModerator() || $this->_oModule->_isAdministrator()) && ($iLoggedId = bx_get_logged_profile_id()) != $iProfileId) {
  708. $aGhostFiles = $oStorage->getGhosts($iLoggedId, $isAssociateWithContent ? 0 : $iContentId, true, $this->_isAdmin($iContentId));
  709. if(!empty($aGhostFiles) && is_array($aGhostFiles))
  710. foreach($aGhostFiles as $aFile) {
  711. if(is_array($mixedFileIds) && !in_array($aFile['id'], $mixedFileIds))
  712. continue;
  713. if($aFile['private'])
  714. $oStorage->setFilePrivate ($aFile['id'], 1);
  715. if($iContentId)
  716. $this->_associalFileWithContent($oStorage, $aFile['id'], $iProfileId, $iContentId, $sFieldFile);
  717. }
  718. }
  719. if($iContentId)
  720. $this->_processTrackFields($iContentId);
  721. return true;
  722. }
  723. public function processFileDeletion ($sFieldFile, $iFileId)
  724. {
  725. if(!isset($this->aInputs[$sFieldFile], $this->aInputs[$sFieldFile]['storage_object']))
  726. return false;
  727. return $this->_deleteFile($iFileId, $this->aInputs[$sFieldFile]['storage_object']);
  728. }
  729. public function processPolls ($sFieldPoll, $iContentId = 0)
  730. {
  731. $CNF = &$this->_oModule->_oConfig->CNF;
  732. if (!isset($this->aInputs[$sFieldPoll]))
  733. return true;
  734. $aPollIds = $this->getCleanValue($sFieldPoll);
  735. if(empty($aPollIds) || !is_array($aPollIds))
  736. return true;
  737. $iProfileId = $this->getContentOwnerProfileId($iContentId);
  738. $aPollsDbIds = $this->_oModule->_oDb->getPolls(array('type' => 'content_id_ids', 'content_id' => $iContentId));
  739. //--- Remove deleted
  740. $this->_oModule->_oDb->deletePollsByIds(array_diff($aPollsDbIds, $aPollIds));
  741. //--- Add new
  742. if($iContentId) {
  743. $aPollsAddIds = array_diff($aPollIds, $aPollsDbIds);
  744. foreach($aPollsAddIds as $iPollId)
  745. $this->_oModule->_oDb->updatePolls(array($CNF['FIELD_POLL_CONTENT_ID'] => $iContentId), array($CNF['FIELD_POLL_ID'] => $iPollId, $CNF['FIELD_POLL_CONTENT_ID'] => 0));
  746. }
  747. return true;
  748. }
  749. function _deleteFile ($iFileId, $sStorage = '')
  750. {
  751. $CNF = &$this->_oModule->_oConfig->CNF;
  752. if(!$iFileId)
  753. return true;
  754. $oStorage = BxDolStorage::getObjectInstance($sStorage ?: $CNF['OBJECT_STORAGE']);
  755. if(!$oStorage)
  756. return false;
  757. if(!$oStorage->getFile($iFileId))
  758. return true;
  759. $iProfileId = bx_get_logged_profile_id();
  760. return $oStorage->deleteFile($iFileId, $iProfileId);
  761. }
  762. function addCssJs ()
  763. {
  764. if ((!isset($this->aParams['view_mode']) || !$this->aParams['view_mode']) && !self::$_isCssJsGeneralModuleAdded) {
  765. $this->_oModule->_oTemplate->addCss('forms.css');
  766. $this->_oModule->_oTemplate->addJs('modules/base/general/js/|forms.js');
  767. self::$_isCssJsGeneralModuleAdded = true;
  768. }
  769. return parent::addCssJs ();
  770. }
  771. function addCssJsPolls($bDynamicMode = false)
  772. {
  773. $sInclude = '';
  774. $sInclude .= $this->_oModule->_oTemplate->addCss(['polls.css'], $bDynamicMode);
  775. $sInclude .= $this->_oModule->_oTemplate->addJs(['modules/base/general/js/|polls.js'], $bDynamicMode);
  776. return $bDynamicMode ? $sInclude : '';
  777. }
  778. function genViewRowValue(&$aInput)
  779. {
  780. $s = parent::genViewRowValue($aInput);
  781. if ($this->_oMetatagsObject && in_array($aInput['name'], $this->_aMetatagsFieldsWithKeywords) && $s)
  782. $s = $this->_oMetatagsObject->metaParse($this->_oMetatagsContentId, $s);
  783. return $s;
  784. }
  785. function genViewRowWrapped(&$aInput)
  786. {
  787. $sResult = parent::genViewRowWrapped($aInput);
  788. if(empty($aInput['rateable']))
  789. return $sResult;
  790. $sValue = $this->genViewRowValue($aInput);
  791. if(null === $sValue)
  792. return '';
  793. // process rateable fields
  794. $iId = BxDolFormQuery::getFormField($this->id, $aInput['name'], $this->_iContentId);
  795. if(($oVote = BxDolVote::getObjectInstance($aInput['rateable'], $iId)) !== null) {
  796. $sVoteElement = $oVote->getElementInline(['show_counter_empty' => true, 'show_counter' => false, 'show_counter_style' => 'simple', 'dynamic_mode' => $this->_bDynamicMode]);
  797. $sVoteCounter = $oVote->getCounter(['show_counter_empty' => true, 'show_counter' => true, 'show_counter_style' => 'simple', 'dynamic_mode' => $this->_bDynamicMode]);
  798. return $this->oTemplate->parseHtmlByName('form_view_rateable_row.html', [
  799. 'value' => $sResult,
  800. 'rate_btn' => $sVoteElement,
  801. 'rate' => $sVoteCounter,
  802. ]);
  803. }
  804. return $sResult;
  805. }
  806. function setMetatagsKeywordsData($iId, $a, $o)
  807. {
  808. $this->_oMetatagsContentId = $iId;
  809. $this->_aMetatagsFieldsWithKeywords = $a;
  810. $this->_oMetatagsObject = $o;
  811. }
  812. function getContentOwnerProfileId ($iContentId)
  813. {
  814. return $this->_oModule->serviceGetContentOwnerProfileId($iContentId);
  815. }
  816. protected function _processTrackFields($mixedContent)
  817. {
  818. if(empty($mixedContent) || empty($this->_aTrackFieldsChanges))
  819. return;
  820. if(!is_array($mixedContent)) {
  821. $mixedContent = $this->_oModule->_oDb->getEntriesBy(['type' => 'id', 'id' => (int)$mixedContent]);
  822. if(empty($mixedContent) || !is_array($mixedContent))
  823. return;
  824. }
  825. foreach($this->_aTrackFieldsChanges as $sField => $aValues)
  826. if($mixedContent[$sField] != $aValues['old'])
  827. $this->_aTrackFieldsChanges[$sField] = array_merge($this->_aTrackFieldsChanges[$sField], [
  828. 'new' => $mixedContent[$sField],
  829. 'result' => true
  830. ]);
  831. else
  832. $this->_aTrackFieldsChanges[$sField]['result'] = false;
  833. }
  834. protected function _processMetas(&$aValsToAdd)
  835. {
  836. $CNF = &$this->_oModule->_oConfig->CNF;
  837. $sKey = 'FIELD_LABELS';
  838. if(isset($CNF[$sKey]) && isset($this->aInputs[$CNF[$sKey]]) && empty($aValsToAdd[$CNF[$sKey]])) {
  839. $aLabels = $this->getCleanValue($CNF[$sKey]);
  840. if(!empty($aLabels) && is_array($aLabels))
  841. $aValsToAdd[$CNF[$sKey]] = serialize($aLabels);
  842. else
  843. $aValsToAdd[$CNF[$sKey]] = '';
  844. }
  845. $sKey1 = 'FIELD_LOCATION';
  846. $sKey2 = 'FIELD_LOCATION_PREFIX';
  847. if(isset($CNF[$sKey1]) && isset($CNF[$sKey2]) && isset($this->aInputs[$CNF[$sKey1]]) && empty($aValsToAdd[$CNF[$sKey1]])) {
  848. $aLocation = BxDolMetatags::locationsRetrieveFromForm($CNF[$sKey2], $this);
  849. if(!empty($aLocation) && is_array($aLocation))
  850. $aValsToAdd[$CNF[$sKey1]] = serialize(BxDolMetatags::locationsParseComponents($aLocation));
  851. }
  852. }
  853. protected function _getPrivacyFields($aKeysF2O = array())
  854. {
  855. $CNF = &$this->_oModule->_oConfig->CNF;
  856. if(isset($CNF['PRIVACY_FIELD_TO_OBJECT']) && is_array($CNF['PRIVACY_FIELD_TO_OBJECT']))
  857. return $CNF['PRIVACY_FIELD_TO_OBJECT'];
  858. if(empty($aKeysF2O))
  859. $aKeysF2O = array('FIELD_ALLOW_VIEW_TO' => 'OBJECT_PRIVACY_VIEW');
  860. $aResult = array();
  861. foreach($aKeysF2O as $sKeyField => $sKeyObject) {
  862. if(!isset($CNF[$sKeyField]) || !isset($this->aInputs[$CNF[$sKeyField]]) || !isset($CNF[$sKeyObject]))
  863. continue;
  864. $aResult[$CNF[$sKeyField]] = $CNF[$sKeyObject];
  865. }
  866. return $aResult;
  867. }
  868. function _addCssJsPrivacyField($sField, $sPrivacyObject, $bDynamicMode = false)
  869. {
  870. $oPrivacy = BxDolPrivacy::getObjectInstance($sPrivacyObject);
  871. if(!$oPrivacy)
  872. return;
  873. $this->aInputs[$sField]['content'] = $oPrivacy->addCssJs($bDynamicMode) . $this->aInputs[$sField]['content'];
  874. }
  875. protected function _preparePrivacyField($sField, $sPrivacyObject)
  876. {
  877. $oPrivacy = BxDolPrivacy::getObjectInstance($sPrivacyObject);
  878. if(!$oPrivacy)
  879. return;
  880. $aSave = array('db' => array('pass' => 'Xss'));
  881. array_walk($this->aInputs[$sField], function ($a, $k, $aSave) {
  882. if (in_array($k, array('info', 'caption', 'value')))
  883. $aSave[0][$k] = $a;
  884. }, array(&$aSave));
  885. $aGroupChooser = $oPrivacy->getGroupChooser($sPrivacyObject, 0, array(
  886. 'object' => $this->aParams['object'],
  887. 'display' => $this->aParams['display']
  888. ));
  889. if (bx_get('context') && isset($aGroupChooser['values'])) {
  890. $bFound = false;
  891. foreach ($aGroupChooser['values'] as $k => $r) {
  892. if (!isset($r['key']) || abs((int)bx_get('context')) !== abs((int)$r['key']))
  893. continue;
  894. $bFound = true;
  895. break;
  896. }
  897. if ($bFound) {
  898. $aSave['type'] = 'hidden';
  899. $aSave['value'] = -abs((int)bx_get('context'));
  900. }
  901. }
  902. $this->aInputs[$sField] = array_merge($this->aInputs[$sField], $aGroupChooser, $aSave);
  903. }
  904. protected function _preloadPrivacyField($sField, $sPrivacyObject, $aValues)
  905. {
  906. $CNF = &$this->_oModule->_oConfig->CNF;
  907. $oPrivacy = BxDolPrivacy::getObjectInstance($sPrivacyObject);
  908. if(!$oPrivacy)
  909. return;
  910. $iContentId = !empty($aValues[$CNF['FIELD_ID']]) ? (int)$aValues[$CNF['FIELD_ID']] : 0;
  911. $iProfileId = !empty($iContentId) ? (int)$this->getContentOwnerProfileId($iContentId) : bx_get_logged_profile_id();
  912. $iGroupId = !empty($aValues[$sField]) ? $aValues[$sField] : 0;
  913. if(!$this->_bIsApi) {
  914. if(!isset($this->aInputs[$sField]['content']))
  915. $this->aInputs[$sField]['content'] = '';
  916. $this->aInputs[$sField]['content'] .= $oPrivacy->initGroupChooser($sPrivacyObject, $iProfileId, [
  917. 'content_id' => $iContentId,
  918. 'group_id' => $iGroupId,
  919. 'html_ids' => [
  920. 'form' => $this->getId()
  921. ]
  922. ]);
  923. }
  924. else
  925. $this->aInputs[$sField]['subvalue'] = $oPrivacy->initGroupChooserAPI($sPrivacyObject, $iProfileId, [
  926. 'content_id' => $iContentId,
  927. 'group_id' => $iGroupId,
  928. ]);
  929. }
  930. protected function _validatePrivacyField($sField, $sPrivacyObject, $aValues)
  931. {
  932. $mixedValue = $this->aInputs[$sField]['value'];
  933. $bValue = false;
  934. foreach($this->aInputs[$sField]['values'] as $aValue)
  935. if(isset($aValue['key']) && $aValue['key'] == $mixedValue) {
  936. $bValue = true;
  937. break;
  938. }
  939. if(!$bValue) {
  940. $sTitle = '';
  941. if(is_numeric($mixedValue) && (int)$mixedValue < 0 && ($oContext = BxDolProfile::getInstance(abs((int)$mixedValue))) !== false)
  942. $sTitle = $oContext->getDisplayName();
  943. else
  944. $sTitle = _t('_sys_ps_group_title_unknown');
  945. $this->aInputs[$sField]['values'] = array_merge(array(
  946. array('key' => $mixedValue, 'value' => $sTitle),
  947. array('key' => '', 'value' => '----', 'attrs' => array('disabled' => 'disabled'))
  948. ), $this->aInputs[$sField]['values']);
  949. }
  950. }
  951. protected function _processContextBeforeAdd()
  952. {
  953. $CNF = &$this->_oModule->_oConfig->CNF;
  954. $sKey = 'FIELD_ALLOW_VIEW_TO';
  955. if(!isset($CNF[$sKey], $this->aInputs[$CNF[$sKey]]))
  956. return;
  957. if(($iContextId = bx_get('context_pid')) !== false)
  958. $this->aInputs[$CNF[$sKey]] = array_merge($this->aInputs[$CNF[$sKey]], [
  959. 'type' => 'hidden',
  960. 'value' => -abs((int)$iContextId)
  961. ]);
  962. $sKey = 'context_nid';
  963. if(($iNodeId = bx_get($sKey)) !== false && !isset($this->aInputs[$sKey])) {
  964. $this->aInputs[$sKey] = [
  965. 'name' => $sKey,
  966. 'type' => 'hidden',
  967. 'value' => (int)$iNodeId
  968. ];
  969. }
  970. $sKey = 'context_usage';
  971. if(($iUsage = bx_get($sKey)) !== false && !isset($this->aInputs[$sKey])) {
  972. $this->aInputs[$sKey] = [
  973. 'name' => $sKey,
  974. 'type' => 'hidden',
  975. 'value' => (int)$iUsage
  976. ];
  977. }
  978. }
  979. protected function _processContextAfterAdd($iContentId, $iContextNid, $iContextUsage = 0)
  980. {
  981. $CNF = &$this->_oModule->_oConfig->CNF;
  982. $sKey = 'FIELD_ALLOW_VIEW_TO';
  983. if(!isset($CNF[$sKey]))
  984. return;
  985. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  986. if(!is_numeric($aContentInfo[$CNF[$sKey]]) || (int)$aContentInfo[$CNF[$sKey]] > 0)
  987. return;
  988. $iContextPid = abs($aContentInfo[$CNF[$sKey]]);
  989. $oContext = BxDolProfile::getInstance($iContextPid);
  990. if(!$oContext)
  991. return;
  992. $sModule = $oContext->getModule();
  993. $sMethod = 'on_content_added';
  994. if(bx_is_srv($sModule, $sMethod))
  995. bx_srv($sModule, $sMethod, [$this->MODULE, $iContentId, $oContext->getContentId(), $iContextNid, $iContextUsage]);
  996. }
  997. /**
  998. *
  999. * MultiCategories related methods.
  1000. *
  1001. */
  1002. protected function processMulticatBefore($sFieldName, &$aValsToAdd)
  1003. {
  1004. if(!isset($this->aInputs[$sFieldName]))
  1005. return;
  1006. if($this->_bIsApi && is_string($this->aInputs[$sFieldName]['value']))
  1007. $this->aInputs[$sFieldName]['value'] = explode(',', $this->aInputs[$sFieldName]['value']);
  1008. $this->aInputs[$sFieldName]['value'] = array_unique(array_filter($this->aInputs[$sFieldName]['value'], function($sTmp) {
  1009. return trim($sTmp);
  1010. }));
  1011. $aValsToAdd[$sFieldName] = implode(',', $this->aInputs[$sFieldName]['value']);
  1012. }
  1013. protected function processMulticatAfter($sFieldName, $iContentId)
  1014. {
  1015. if(!isset($this->aInputs[$sFieldName]))
  1016. return;
  1017. $CNF = &$this->_oModule->_oConfig->CNF;
  1018. $sModule = $this->_oModule->getName();
  1019. $bAutoActivation = (($sKey = 'PARAM_MULTICAT_AUTO_ACTIVATION_FOR_CATEGORIES') && isset($CNF[$sKey]) && getParam($CNF[$sKey]) == 'on');
  1020. $oCategories = BxDolCategories::getInstance();
  1021. $oCategories->delete($sModule, $iContentId);
  1022. foreach($this->aInputs[$sFieldName]['value'] as $sValue)
  1023. $oCategories->add($sModule, bx_get_logged_profile_id(), $sValue, $iContentId, $bAutoActivation);
  1024. }
  1025. protected function genCustomViewRowValueMulticat(&$aInput)
  1026. {
  1027. $oCategories = BxDolCategories::getInstance();
  1028. $aValues = $oCategories->getData(array('type' => 'by_module_and_object', 'module' => $this->_oModule->getName(), 'object_id' => (!empty($aInput['content_id']) ? (int)$aInput['content_id'] : 0 )));
  1029. if (count($aValues) > 0){
  1030. $aVars = array('bx_repeat:cats' => array());
  1031. foreach ($aValues as $sValue) {
  1032. $aVars['bx_repeat:cats'][] = array(
  1033. 'url' => $oCategories->getUrl($this->_oModule->getName(), $sValue),
  1034. 'name' => _t($sValue),
  1035. 'bx_if:more' => array(
  1036. 'condition' => $sValue === end($aValues) ? false : true,
  1037. 'content' => array('1')
  1038. ),
  1039. );
  1040. }
  1041. if (!$aVars['bx_repeat:cats'])
  1042. return '';
  1043. return $this->_oModule->_oTemplate->parseHtmlByName('category_list_inline.html', $aVars);
  1044. }
  1045. return '';
  1046. }
  1047. protected function genCustomInputMulticat(&$aInput)
  1048. {
  1049. $aValuesForSelect = BxDolCategories::getInstance()->getData([
  1050. 'type' => 'by_module_and_author',
  1051. 'module' => $this->_oModule->getName(),
  1052. 'author' => bx_get_logged_profile_id()
  1053. ]);
  1054. if(isset($aInput['value']) && is_array($aInput['value']))
  1055. $aInput['value'] = array_filter($aInput['value']);
  1056. $aValues = [];
  1057. if(!empty($aInput['value'])) {
  1058. if (!is_array($aInput['value']))
  1059. $aValues = BxDolCategories::getInstance()->getData([
  1060. 'type' => 'by_module_and_object',
  1061. 'module' => $this->_oModule->getName(),
  1062. 'object_id' => (!empty($aInput['content_id']) ? (int)$aInput['content_id'] : 0 )
  1063. ]);
  1064. else
  1065. $aValues = $aInput['value'];
  1066. $aValues = array_filter($aValues);
  1067. foreach($aValues as $sValue)
  1068. if(!array_key_exists($sValue, $aValuesForSelect))
  1069. $aValuesForSelect[$sValue] = [
  1070. 'key' => $sValue,
  1071. 'value' => $sValue
  1072. ];
  1073. }
  1074. if($this->_bIsApi) {
  1075. array_walk($aValuesForSelect, function(&$aValue, $sKey) {
  1076. $aValue['value'] = _t($aValue['key']);
  1077. });
  1078. return array_merge($aInput, [
  1079. 'type' => 'select_multiple',
  1080. 'values' => array_values($aValuesForSelect),
  1081. 'value' => $aValues
  1082. ]);
  1083. }
  1084. $sJsObject = $this->_oModule->_oConfig->getJsObject('categories');
  1085. $aSelectedItems = [];
  1086. if(!empty($aValues))
  1087. foreach($aValues as $sValue)
  1088. $aSelectedItems[] = [
  1089. 'js_object' => $sJsObject,
  1090. 'select_cat' => $this->genCustomInputMulticatSelect($aInput, $aValuesForSelect, $sValue)
  1091. ];
  1092. else
  1093. $aSelectedItems[] = [
  1094. 'js_object' => $sJsObject,
  1095. 'select_cat' => $this->genCustomInputMulticatSelect($aInput, $aValuesForSelect)
  1096. ];
  1097. return $this->_oModule->_oTemplate->parseHtmlByName('form_categories.html', array(
  1098. 'bx_repeat:items' => $aSelectedItems,
  1099. 'js_object' => $sJsObject,
  1100. 'select_cat' => $this->genCustomInputMulticatSelect($aInput, $aValuesForSelect, -1),
  1101. 'input_cat' => $this->genCustomInputMulticatInput($aInput),
  1102. 'js_object' => $sJsObject,
  1103. 'btn_add' => $this->genCustomInputMulticatButton($aInput),
  1104. 'btn_add_new' => $this->genCustomInputMulticatButtonNew($aInput)
  1105. ));
  1106. }
  1107. protected function genCustomInputMulticatSelect($aInput, $aValues, $mixedValue = '')
  1108. {
  1109. foreach($aValues as $sKey => $aValue) {
  1110. $aValues[$sKey]['value'] = _t($aValue['key']);
  1111. }
  1112. $aValues = array_merge(array('1' => array('key' => false, 'value' => _t('_sys_please_select'))), $aValues);
  1113. $aInput['type'] = 'select';
  1114. $aInput['name'] .= '[]';
  1115. $aInput['value'] = $mixedValue;
  1116. $aInput['values'] = $aValues;
  1117. return $this->genInput($aInput);
  1118. }
  1119. protected function genCustomInputMulticatInput($aInput)
  1120. {
  1121. $aInput['type'] = 'text';
  1122. $aInput['name'] .= '[]';
  1123. $aInput['value'] = '';
  1124. return $this->genInput($aInput);
  1125. }
  1126. protected function genCustomInputMulticatButton($aInput)
  1127. {
  1128. $sName = $aInput['name'];
  1129. $aInput['type'] = 'button';
  1130. $aInput['name'] .= '_add';
  1131. $aInput['value'] = _t('_sys_txt_categories_button_caption_add');
  1132. $aInput['attrs']['class'] = 'bx-def-margin-right bx-def-margin-sec-top';
  1133. $aInput['attrs']['onclick'] = $this->_oModule->_oConfig->getJsObject('categories') . ".categoryAdd(this, '" . $sName . "');";
  1134. return $this->genInputButton($aInput);
  1135. }
  1136. protected function genCustomInputMulticatButtonNew($aInput)
  1137. {
  1138. $sName = $aInput['name'];
  1139. $aInput['type'] = 'button';
  1140. $aInput['name'] .= '_add';
  1141. $aInput['value'] = _t('_sys_txt_categories_button_caption_addnew');
  1142. $aInput['attrs']['class'] = 'bx-def-margin-sec-top';
  1143. $aInput['attrs']['onclick'] = $this->_oModule->_oConfig->getJsObject('categories') . ".categoryAddNew(this, '" . $sName . "');";
  1144. return $this->genInputButton($aInput);
  1145. }
  1146. protected function genCustomInputAuthor ($aInput)
  1147. {
  1148. if(empty($aInput['custom']) || !is_array($aInput['custom']))
  1149. $aInput['custom'] = array();
  1150. $aInput['custom']['only_once'] = 1;
  1151. $aInput['ajax_get_suggestions'] = BX_DOL_URL_ROOT . "modules/?r=" . $this->_oModule->_oConfig->getUri() . "/ajax_get_profiles";
  1152. if (bx_is_api()){
  1153. $aInput['ajax_get_suggestions'] = $this->_oModule->_oConfig->getName() . "/get_profiles&params[]=";
  1154. $aProfile = BxDolProfile::getInstance($aInput['value'])->getUnitAPI(0, ['template' => 'unit_wo_info']);
  1155. $aInput['value_data'] = [$aProfile['author_data']];
  1156. }
  1157. return $this->genCustomInputUsernamesSuggestions($aInput);
  1158. }
  1159. protected function genCustomInputPolls ($aInput)
  1160. {
  1161. $mixedResult = $this->_oModule->_oTemplate->getPollField(!empty($aInput['content_id']) ? (int)$aInput['content_id'] : 0);
  1162. $sModule = $this->_oModule->getName();
  1163. return $this->_bIsApi ? array_merge($aInput, [
  1164. 'type' => 'polls',
  1165. 'value' => implode(',', array_column($mixedResult, 'id')),
  1166. 'values' => $mixedResult,
  1167. 'request_get' => '/api.php?r=' . $sModule . '/get_poll_form',
  1168. 'request_submit' => '/api.php?r=' . $sModule . '/submit_poll_form',
  1169. 'request_remove' => '/api.php?r=' . $sModule . '/delete_poll',
  1170. 'request_results' => '/api.php?r=' . $sModule . '/get_block_poll_results',
  1171. ]) : $mixedResult;
  1172. }
  1173. protected function _isMulticatEnabled(){
  1174. $CNF = $this->_oModule->_oConfig->CNF;
  1175. return isset($CNF['PARAM_MULTICAT_ENABLED']) && $CNF['PARAM_MULTICAT_ENABLED'] === true && isset($CNF['FIELD_MULTICAT']);
  1176. }
  1177. protected function _replaceMarkersInControls($sKey = 'controls')
  1178. {
  1179. if(!isset($this->aInputs[$sKey]) || !is_array($this->aInputs[$sKey]))
  1180. return;
  1181. array_walk($this->aInputs[$sKey], function(&$aItem, $mKey) {
  1182. if(!is_int($mKey))
  1183. return;
  1184. if(!empty($aItem['attrs']) && is_array($aItem['attrs']))
  1185. $aItem['attrs'] = $this->_replaceMarkers($aItem['attrs']);
  1186. });
  1187. }
  1188. }
  1189. /** @} */