1
0

BxBaseCmtsForm.php 6.2 KB

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