| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup BaseText Base classes for text modules
- * @ingroup UnaModules
- *
- * @{
- */
- /**
- * Create/Edit entry form
- */
- class BxBaseModTextFormEntry extends BxBaseModGeneralFormEntry
- {
- protected $_sGhostTemplate = 'form_ghost_template.html';
- public function __construct($aInfo, $oTemplate = false)
- {
- parent::__construct($aInfo, $oTemplate);
- $CNF = &$this->_oModule->_oConfig->CNF;
- if (isset($this->aInputs[$CNF['FIELD_TEXT']])) {
- $this->aInputs[$CNF['FIELD_TEXT']]['attrs'] = array_merge (
- array ('id' => $CNF['FIELD_TEXT_ID']),
- is_array($this->aInputs[$CNF['FIELD_TEXT']]['attrs']) ? $this->aInputs[$CNF['FIELD_TEXT']]['attrs'] : array ()
- );
- }
- if (isset($this->aInputs[$CNF['FIELD_PHOTO']])) {
- $this->aInputs[$CNF['FIELD_PHOTO']]['storage_object'] = $CNF['OBJECT_STORAGE'];
- $this->aInputs[$CNF['FIELD_PHOTO']]['uploaders'] = !empty($this->aInputs[$CNF['FIELD_PHOTO']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_PHOTO']]['value']) : $CNF['OBJECT_UPLOADERS'];
- $this->aInputs[$CNF['FIELD_PHOTO']]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW'];
- $this->aInputs[$CNF['FIELD_PHOTO']]['storage_private'] = 0;
- $this->aInputs[$CNF['FIELD_PHOTO']]['multiple'] = true;
- $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'] = 0;
- $this->aInputs[$CNF['FIELD_PHOTO']]['ghost_template'] = '';
- }
- if (isset($this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']]))
- $this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']] = BxDolPrivacy::getGroupChooser($CNF['OBJECT_PRIVACY_VIEW']);
- if (isset($this->aInputs['do_publish']) && !isset($this->aInputs['do_submit']))
- $this->aParams['db']['submit_name'] = 'do_publish';
- }
- function initChecker ($aValues = array (), $aSpecificValues = array())
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if (isset($this->aInputs[$CNF['FIELD_PHOTO']])) {
- $aContentInfo = false;
- if ($aValues && !empty($aValues['id'])) {
- $aContentInfo = $this->_oModule->_oDb->getContentInfoById ($aValues['id']);
- $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'] = $aValues['id'];
- }
- $this->aInputs[$CNF['FIELD_PHOTO']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplate, $this->_getPhotoGhostTmplVars($aContentInfo));
- }
- return parent::initChecker($aValues, $aSpecificValues);
- }
- public function insert ($aValsToAdd = array(), $isIgnore = false)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedSetThumb()) {
- $aThumb = isset($_POST[$CNF['FIELD_THUMB']]) ? bx_process_input ($_POST[$CNF['FIELD_THUMB']], BX_DATA_INT) : false;
- $aValsToAdd[$CNF['FIELD_THUMB']] = 0;
- if (!empty($aThumb) && is_array($aThumb) && ($iFileThumb = array_pop($aThumb)))
- $aValsToAdd[$CNF['FIELD_THUMB']] = $iFileThumb;
- }
- $iContentId = parent::insert ($aValsToAdd, $isIgnore);
- if(!empty($iContentId))
- $this->processFiles ($CNF['FIELD_PHOTO'], $iContentId, true);
- return $iContentId;
- }
- function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedSetThumb()) {
- $aThumb = bx_process_input (bx_get($CNF['FIELD_THUMB']), BX_DATA_INT);
- $aValsToAdd[$CNF['FIELD_THUMB']] = 0;
- if (!empty($aThumb) && is_array($aThumb) && ($iFileThumb = array_pop($aThumb)))
- $aValsToAdd[$CNF['FIELD_THUMB']] = $iFileThumb;
- }
- $iRet = parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
- $this->processFiles ($CNF['FIELD_PHOTO'], $iContentId, false);
- return $iRet;
- }
- function _deleteFile ($iFileId, $sStorage = '')
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if (!$iFileId)
- return true;
- $sStorage = !empty($sStorage) ? $sStorage : $CNF['OBJECT_STORAGE'];
- $oStorage = BxDolStorage::getObjectInstance($sStorage);
- if (!$oStorage)
- return false;
- if (!$oStorage->getFile($iFileId))
- return true;
- $iProfileId = bx_get_logged_profile_id();
- return $oStorage->deleteFile($iFileId, $iProfileId);
- }
- protected function _associalFileWithContent($oStorage, $iFileId, $iProfileId, $iContentId, $sPictureField = '')
- {
- $oStorage->updateGhostsContentId ($iFileId, $iProfileId, $iContentId);
- }
- protected function _getPhotoGhostTmplVars($aContentInfo = array())
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- return array (
- 'name' => $this->aInputs[$CNF['FIELD_PHOTO']]['name'],
- 'content_id' => $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'],
- 'editor_id' => $CNF['FIELD_TEXT_ID'],
- 'thumb_id' => isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) ? $aContentInfo[$CNF['FIELD_THUMB']] : 0,
- 'bx_if:set_thumb' => array (
- 'condition' => CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedSetThumb(),
- 'content' => array (
- 'name_thumb' => isset($CNF['FIELD_THUMB']) ? $CNF['FIELD_THUMB'] : '',
- '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')
- ),
- ),
- );
- }
- }
- /** @} */
|