BxBaseCmtsForm.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. class BxBaseCmtsForm extends BxTemplFormView
  10. {
  11. protected static $_sAttributeMaskId;
  12. protected static $_sAttributeMaskName;
  13. protected $_oObject;
  14. protected $_sGhostTemplateImage;
  15. public function __construct($aInfo, $oTemplate)
  16. {
  17. parent::__construct($aInfo, $oTemplate);
  18. if(empty(self::$_sAttributeMaskId))
  19. self::$_sAttributeMaskId = $this->aFormAttrs['id'];
  20. if(empty(self::$_sAttributeMaskName))
  21. self::$_sAttributeMaskName = $this->aFormAttrs['name'];
  22. $this->_oObject = null;
  23. $this->_sGhostTemplateImage = 'comments_uploader_nfw.html';
  24. if(isset($this->aInputs['cmt_image'])) {
  25. $this->aInputs['cmt_image']['storage_object'] = 'sys_cmts_images';
  26. $this->aInputs['cmt_image']['images_transcoder'] = 'sys_cmts_images_preview';
  27. $this->aInputs['cmt_image']['uploaders'] = !empty($this->aInputs['cmt_image']['value']) ? unserialize($this->aInputs['cmt_image']['value']) : array('sys_cmts_html5');
  28. $this->aInputs['cmt_image']['upload_buttons_titles'] = array('Simple' => 'camera', 'HTML5' => 'camera');
  29. $this->aInputs['cmt_image']['storage_private'] = 0;
  30. $this->aInputs['cmt_image']['multiple'] = true;
  31. $this->aInputs['cmt_image']['content_id'] = 0;
  32. $this->aInputs['cmt_image']['ghost_template'] = '';
  33. }
  34. }
  35. function getHtmlEditorQueryParams($aInput)
  36. {
  37. $aQueryParams = parent::getHtmlEditorQueryParams($aInput);
  38. if (isset($this->aInputs['id'])){
  39. $aQueryParams['cid'] = $this->aInputs['id']['value'];
  40. }
  41. $aQueryParams['m'] = 'sys_cmts';
  42. $aQueryParams['fi'] = '';
  43. /**
  44. * @hooks
  45. * @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
  46. * - $unit_name - equals `system`
  47. * - $action - equals `editor_query_params`
  48. * - $object_id - not used
  49. * - $sender_id - not used
  50. * - $extra_params - array of additional params with the following array keys:
  51. * - `form` - [object] an instance of form, @see BxDolForm
  52. * - `override_result` - [array] by ref, query string params, can be overridden in hook processing
  53. * @hook @ref hook-system-editor_query_params
  54. */
  55. bx_alert('system', 'editor_query_params', 0, 0, [
  56. 'form' => $this,
  57. 'override_result' => &$aQueryParams
  58. ]);
  59. return $aQueryParams;
  60. }
  61. public function getAttributeMask($sAttribute)
  62. {
  63. $sName = '_sAttributeMask' . bx_gen_method_name($sAttribute);
  64. return isset(self::$$sName) ? self::$$sName : '';
  65. }
  66. public function getStorageObjectName()
  67. {
  68. return isset($this->aInputs['cmt_image']['storage_object']) ? $this->aInputs['cmt_image']['storage_object'] : '';
  69. }
  70. public function getTranscoderPreviewName()
  71. {
  72. return isset($this->aInputs['cmt_image']['images_transcoder']) ? $this->aInputs['cmt_image']['images_transcoder'] : '';
  73. }
  74. function initChecker ($aValues = array (), $aSpecificValues = array())
  75. {
  76. if(isset($this->aInputs['cmt_image'])) {
  77. if(!empty($this->aInputs['sys']['value']) && !empty($this->aInputs['id']['value']) && !empty($aValues['cmt_id'])) {
  78. $oObject = $this->_getObject(bx_process_input($this->aInputs['sys']['value']), (int)$this->aInputs['id']['value']);
  79. if($oObject)
  80. $this->aInputs['cmt_image']['content_id'] = $oObject->getCommentUniqId($aValues['cmt_id']);
  81. }
  82. $this->aInputs['cmt_image']['ghost_template'] = $this->oTemplate->parseHtmlByName($this->_sGhostTemplateImage, $this->_getGhostTmplVarsImage());
  83. }
  84. if (isset($this->aInputs['cmt_anonymous']) && isset($aValues['cmt_author_id']))
  85. $this->aInputs['cmt_anonymous']['checked'] = $aValues['cmt_author_id'] < 0;
  86. parent::initChecker ($aValues, $aSpecificValues);
  87. }
  88. public function insert ($aValsToAdd = array(), $isIgnore = false)
  89. {
  90. $aValsToAdd['cmt_author_id'] *= isset($this->aInputs['cmt_anonymous']) && $this->getCleanValue('cmt_anonymous') ? -1 : 1;
  91. return parent::insert ($aValsToAdd, $isIgnore);
  92. }
  93. public function update ($iCmtId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  94. {
  95. if (isset($this->aInputs['cmt_anonymous'])) {
  96. $aCmt = $this->_getObject($this->getCleanValue('sys'), $this->getCleanValue('id'))->getCommentRow($iCmtId);
  97. $aValsToAdd['cmt_author_id'] = ($this->getCleanValue('cmt_anonymous') ? -1 : 1) * abs($aCmt['cmt_author_id']);
  98. }
  99. return parent::update ($iCmtId, $aValsToAdd, $aTrackTextFieldsChanges);
  100. }
  101. public function processImages ($oCmts, $sFieldName, $iCmtUniqId, $iCmtId, $iCmtAuthorId, $isAssociateWithContent = false)
  102. {
  103. if(!isset($this->aInputs[$sFieldName]))
  104. return true;
  105. $mixedFileIds = $this->getCleanValue($sFieldName);
  106. if(!$mixedFileIds)
  107. return true;
  108. $oStorage = BxDolStorage::getObjectInstance($this->aInputs[$sFieldName]['storage_object']);
  109. if(!$oStorage)
  110. return false;
  111. $aGhostImages = $oStorage->getGhosts($iCmtAuthorId, $isAssociateWithContent ? 0 : $iCmtUniqId, true, $oCmts->isAdmin($iCmtAuthorId));
  112. if(!$aGhostImages)
  113. return true;
  114. foreach($aGhostImages as $aImage) {
  115. if(is_array($mixedFileIds) && !in_array($aImage['id'], $mixedFileIds))
  116. continue;
  117. if($aImage['private'])
  118. $oStorage->setFilePrivate($aImage['id'], 1);
  119. if($iCmtId)
  120. $this->_associalImageWithContent($oCmts, $sFieldName, $iCmtUniqId, $iCmtId, $iCmtAuthorId, $aImage['id']);
  121. }
  122. return true;
  123. }
  124. protected function genCustomRowCmtCf(&$aInput)
  125. {
  126. $aInput = BxDolContentFilter::getInstance()->getInputForComments($aInput);
  127. if($aInput['type'] == 'hidden') {
  128. $this->_sCodeAdd .= $this->genInput($aInput);
  129. return '';
  130. }
  131. return $this->genRowStandard($aInput);
  132. }
  133. protected function _getObject($sSystem, $iId)
  134. {
  135. if(empty($this->_oObject))
  136. $this->_oObject = BxDolCmts::getObjectInstance($sSystem, $iId);
  137. return $this->_oObject;
  138. }
  139. protected function _getGhostTmplVarsImage($aCmt = array())
  140. {
  141. return array (
  142. 'name' => $this->aInputs['cmt_image']['name'],
  143. 'content_id' => (int)$this->aInputs['cmt_image']['content_id'],
  144. 'editor_id' => '',
  145. );
  146. }
  147. protected function _associalImageWithContent($oCmts, $sFieldName, $iCmtUniqId, $iCmtId, $iCmtAuthorId, $iImageId)
  148. {
  149. $oStorage = BxDolStorage::getObjectInstance($this->aInputs[$sFieldName]['storage_object']);
  150. if(!$oStorage)
  151. return false;
  152. $oStorage->updateGhostsContentId($iImageId, $iCmtAuthorId, $iCmtUniqId, $oCmts->isAdmin($iCmtAuthorId));
  153. $aSystem = $oCmts->getSystemInfo();
  154. $oCmts->getQueryObject()->saveImages($aSystem['system_id'], $iCmtId, $iImageId);
  155. return true;
  156. }
  157. }
  158. /** @} */