1
0

BxBaseCmtsForm.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. bx_alert('system', 'editor_query_params', 0, 0, array(
  44. 'form' => $this,
  45. 'override_result' => &$aQueryParams
  46. ));
  47. return $aQueryParams;
  48. }
  49. public function getAttributeMask($sAttribute)
  50. {
  51. $sName = '_sAttributeMask' . bx_gen_method_name($sAttribute);
  52. return isset(self::$$sName) ? self::$$sName : '';
  53. }
  54. public function getStorageObjectName()
  55. {
  56. return isset($this->aInputs['cmt_image']['storage_object']) ? $this->aInputs['cmt_image']['storage_object'] : '';
  57. }
  58. public function getTranscoderPreviewName()
  59. {
  60. return isset($this->aInputs['cmt_image']['images_transcoder']) ? $this->aInputs['cmt_image']['images_transcoder'] : '';
  61. }
  62. function initChecker ($aValues = array (), $aSpecificValues = array())
  63. {
  64. if(isset($this->aInputs['cmt_image'])) {
  65. if(!empty($this->aInputs['sys']['value']) && !empty($this->aInputs['id']['value']) && !empty($aValues['cmt_id'])) {
  66. $oObject = $this->_getObject(bx_process_input($this->aInputs['sys']['value']), (int)$this->aInputs['id']['value']);
  67. if($oObject)
  68. $this->aInputs['cmt_image']['content_id'] = $oObject->getCommentUniqId($aValues['cmt_id']);
  69. }
  70. $this->aInputs['cmt_image']['ghost_template'] = $this->oTemplate->parseHtmlByName($this->_sGhostTemplateImage, $this->_getGhostTmplVarsImage());
  71. }
  72. if (isset($this->aInputs['cmt_anonymous']) && isset($aValues['cmt_author_id']))
  73. $this->aInputs['cmt_anonymous']['checked'] = $aValues['cmt_author_id'] < 0;
  74. parent::initChecker ($aValues, $aSpecificValues);
  75. }
  76. public function insert ($aValsToAdd = array(), $isIgnore = false)
  77. {
  78. $aValsToAdd['cmt_author_id'] *= isset($this->aInputs['cmt_anonymous']) && $this->getCleanValue('cmt_anonymous') ? -1 : 1;
  79. return parent::insert ($aValsToAdd, $isIgnore);
  80. }
  81. public function update ($iCmtId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  82. {
  83. if (isset($this->aInputs['cmt_anonymous'])) {
  84. $aCmt = $this->_getObject($this->getCleanValue('sys'), $this->getCleanValue('id'))->getCommentRow($iCmtId);
  85. $aValsToAdd['cmt_author_id'] = ($this->getCleanValue('cmt_anonymous') ? -1 : 1) * abs($aCmt['cmt_author_id']);
  86. }
  87. return parent::update ($iCmtId, $aValsToAdd, $aTrackTextFieldsChanges);
  88. }
  89. public function processImages ($oCmts, $sFieldName, $iCmtUniqId, $iCmtId, $iCmtAuthorId, $isAssociateWithContent = false)
  90. {
  91. if(!isset($this->aInputs[$sFieldName]))
  92. return true;
  93. $mixedFileIds = $this->getCleanValue($sFieldName);
  94. if(!$mixedFileIds)
  95. return true;
  96. $oStorage = BxDolStorage::getObjectInstance($this->aInputs[$sFieldName]['storage_object']);
  97. if(!$oStorage)
  98. return false;
  99. $aGhostImages = $oStorage->getGhosts($iCmtAuthorId, $isAssociateWithContent ? 0 : $iCmtUniqId, true, $oCmts->isAdmin($iCmtAuthorId));
  100. if(!$aGhostImages)
  101. return true;
  102. foreach($aGhostImages as $aImage) {
  103. if(is_array($mixedFileIds) && !in_array($aImage['id'], $mixedFileIds))
  104. continue;
  105. if($aImage['private'])
  106. $oStorage->setFilePrivate($aImage['id'], 1);
  107. if($iCmtId)
  108. $this->_associalImageWithContent($oCmts, $sFieldName, $iCmtUniqId, $iCmtId, $iCmtAuthorId, $aImage['id']);
  109. }
  110. return true;
  111. }
  112. protected function genCustomRowCmtCf(&$aInput)
  113. {
  114. $aInput = BxDolContentFilter::getInstance()->getInputForComments($aInput);
  115. if($aInput['type'] == 'hidden') {
  116. $this->_sCodeAdd .= $this->genInput($aInput);
  117. return '';
  118. }
  119. return $this->genRowStandard($aInput);
  120. }
  121. protected function _getObject($sSystem, $iId)
  122. {
  123. if(empty($this->_oObject))
  124. $this->_oObject = BxDolCmts::getObjectInstance($sSystem, $iId);
  125. return $this->_oObject;
  126. }
  127. protected function _getGhostTmplVarsImage($aCmt = array())
  128. {
  129. return array (
  130. 'name' => $this->aInputs['cmt_image']['name'],
  131. 'content_id' => (int)$this->aInputs['cmt_image']['content_id'],
  132. 'editor_id' => '',
  133. );
  134. }
  135. protected function _associalImageWithContent($oCmts, $sFieldName, $iCmtUniqId, $iCmtId, $iCmtAuthorId, $iImageId)
  136. {
  137. $oStorage = BxDolStorage::getObjectInstance($this->aInputs[$sFieldName]['storage_object']);
  138. if(!$oStorage)
  139. return false;
  140. $oStorage->updateGhostsContentId($iImageId, $iCmtAuthorId, $iCmtUniqId, $oCmts->isAdmin($iCmtAuthorId));
  141. $aSystem = $oCmts->getSystemInfo();
  142. $oCmts->getQueryObject()->saveImages($aSystem['system_id'], $iCmtId, $iImageId);
  143. return true;
  144. }
  145. }
  146. /** @} */