BxBaseCmtsForm.php 5.9 KB

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