| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup BaseGeneral Base classes for modules
- * @ingroup UnaModules
- *
- * @{
- */
- /**
- * Create/edit entry form
- */
- class BxBaseModGeneralFormEntry extends BxTemplFormView
- {
- protected $MODULE;
- protected $_oModule;
- protected $_aMetatagsFieldsWithKeywords = array();
- protected $_oMetatagsObject = null;
- protected $_oMetatagsContentId = 0;
- public function __construct($aInfo, $oTemplate = false)
- {
- parent::__construct($aInfo, $oTemplate);
- $this->_oModule = BxDolModule::getInstance($this->MODULE);
- $CNF = &$this->_oModule->_oConfig->CNF;
-
- if (isset($CNF['FIELD_ADDED']) && isset($this->aInputs[$CNF['FIELD_ADDED']])) {
- $this->aInputs[$CNF['FIELD_ADDED']]['date_filter'] = BX_DATA_INT;
- $this->aInputs[$CNF['FIELD_ADDED']]['date_format'] = BX_FORMAT_DATE;
- }
- if (isset($CNF['FIELD_CHANGED']) && isset($this->aInputs[$CNF['FIELD_CHANGED']])) {
- $this->aInputs[$CNF['FIELD_CHANGED']]['date_filter'] = BX_DATA_INT;
- $this->aInputs[$CNF['FIELD_CHANGED']]['date_format'] = BX_FORMAT_DATE;
- }
- if (isset($CNF['FIELD_LOCATION_PREFIX']) && isset($this->aInputs[$CNF['FIELD_LOCATION_PREFIX']])) {
- $this->aInputs[$CNF['FIELD_LOCATION_PREFIX']]['manual_input'] = true;
- }
- }
- function initChecker ($aValues = array (), $aSpecificValues = array())
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if (!empty($CNF['FIELD_LOCATION_PREFIX']) && isset($this->aInputs[$CNF['FIELD_LOCATION_PREFIX']]) && isset($aValues[$CNF['FIELD_ID']]) && !empty($CNF['OBJECT_METATAGS']) && ($oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS'])) && $oMetatags->locationsIsEnabled())
- $this->aInputs[$CNF['FIELD_LOCATION_PREFIX']]['value'] = $oMetatags->locationsString($aValues[$CNF['FIELD_ID']], false);
- parent::initChecker ($aValues, $aSpecificValues);
- }
-
- public function insert ($aValsToAdd = array(), $isIgnore = false)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if (isset($CNF['FIELD_AUTHOR']) && empty($aValsToAdd[$CNF['FIELD_AUTHOR']]))
- $aValsToAdd[$CNF['FIELD_AUTHOR']] = bx_get_logged_profile_id ();
- if (isset($CNF['FIELD_ADDED']) && empty($aValsToAdd[$CNF['FIELD_ADDED']]))
- $aValsToAdd[$CNF['FIELD_ADDED']] = time();
- if (isset($CNF['FIELD_CHANGED']) && empty($aValsToAdd[$CNF['FIELD_CHANGED']]))
- $aValsToAdd[$CNF['FIELD_CHANGED']] = time();
- return parent::insert ($aValsToAdd, $isIgnore);
- }
- function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if (isset($CNF['FIELD_CHANGED']))
- $aValsToAdd[$CNF['FIELD_CHANGED']] = time();
-
- return parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
- }
- function delete ($iContentId, $aContentInfo = array())
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- // delete associated files
- if (!empty($CNF['OBJECT_STORAGE'])) {
- $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
- if ($oStorage)
- $oStorage->queueFilesForDeletionFromGhosts($aContentInfo[$CNF['FIELD_AUTHOR']], $iContentId);
- }
- // delete associated objects data
- if (!empty($CNF['OBJECT_VIEWS'])) {
- $o = BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $iContentId);
- if ($o) $o->onObjectDelete();
- }
- if (!empty($CNF['OBJECT_VOTES'])) {
- $o = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
- if ($o) $o->onObjectDelete();
- }
- if (!empty($CNF['OBJECT_COMMENTS'])) {
- $o = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
- if ($o) $o->onObjectDelete();
- }
- if (!empty($CNF['OBJECT_METATAGS'])) {
- $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
- $oMetatags->onDeleteContent($iContentId);
- }
- // delete db record
- return parent::delete($iContentId);
- }
- public function processFiles ($sFieldFile, $iContentId = 0, $isAssociateWithContent = false)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if (!isset($this->aInputs[$sFieldFile]))
- return true;
- $mixedFileIds = $this->getCleanValue($sFieldFile);
- if(!$mixedFileIds)
- return true;
- $oStorage = BxDolStorage::getObjectInstance($this->aInputs[$sFieldFile]['storage_object']);
- if (!$oStorage)
- return false;
- $iProfileId = $this->getContentOwnerProfileId($iContentId);
- $aGhostFiles = $oStorage->getGhosts ($iProfileId, $isAssociateWithContent ? 0 : $iContentId, true);
- if (!$aGhostFiles)
- return true;
- foreach ($aGhostFiles as $aFile) {
- if (is_array($mixedFileIds) && !in_array($aFile['id'], $mixedFileIds))
- continue;
- if ($aFile['private'])
- $oStorage->setFilePrivate ($aFile['id'], 0);
- if ($iContentId)
- $this->_associalFileWithContent($oStorage, $aFile['id'], $iProfileId, $iContentId, $sFieldFile);
- }
- return true;
- }
- function addCssJs ()
- {
- if (!isset($this->aParams['view_mode']) || !$this->aParams['view_mode']) {
- if (self::$_isCssJsAdded)
- return;
- $this->_oModule->_oTemplate->addCss('forms.css');
- $this->_oModule->_oTemplate->addJs('modules/base/general/js/|forms.js');
- }
- return parent::addCssJs ();
- }
-
- function genViewRowValue(&$aInput)
- {
- $s = parent::genViewRowValue($aInput);
- if ($this->_oMetatagsObject && in_array($aInput['name'], $this->_aMetatagsFieldsWithKeywords) && $s)
- $s = $this->_oMetatagsObject->keywordsParse($this->_oMetatagsContentId, $s);
- return $s;
- }
- function setMetatagsKeywordsData($iId, $a, $o)
- {
- $this->_oMetatagsContentId = $iId;
- $this->_aMetatagsFieldsWithKeywords = $a;
- $this->_oMetatagsObject = $o;
- }
- function getContentOwnerProfileId ($iContentId)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- // file owner must be author of the content or profile itself in case of profile based module
- if ($iContentId) {
- if ($this->_oModule instanceof iBxDolProfileService) {
- $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->MODULE);
- }
- else {
- $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
- $oProfile = $aContentInfo ? BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]) : null;
- }
- $iProfileId = $oProfile ? $oProfile->id() : bx_get_logged_profile_id();
- }
- else {
- $iProfileId = bx_get_logged_profile_id();
- }
- return $iProfileId;
- }
- }
- /** @} */
|