| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- <?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 $_sGhostTemplateVideo = 'form_ghost_template_video.html';
- protected $_sGhostTemplateFile = 'form_ghost_template_file.html';
- public function __construct($aInfo, $oTemplate = false)
- {
- parent::__construct($aInfo, $oTemplate);
- }
- function getCode($bDynamicMode = false)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- $sResult = parent::getCode($bDynamicMode);
- if(!empty($CNF['OBJECT_MENU_ENTRY_ATTACHMENTS']))
- $sResult = $this->_oModule->_oTemplate->parseHtmlByContent($sResult, array(
- 'attachments_menu' => BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_ENTRY_ATTACHMENTS'])->getCode()
- ));
- if(isset($CNF['PARAM_POLL_ENABLED']) && $CNF['PARAM_POLL_ENABLED'] === true) {
- $sInclude = '';
- $sInclude .= $this->_oModule->_oTemplate->addCss(array('polls.css'), $bDynamicMode);
- $sInclude .= $this->_oModule->_oTemplate->addJs(array('polls.js'), $bDynamicMode);
- $sResult .= ($bDynamicMode ? $sInclude : '') . $this->_oModule->_oTemplate->getJsCode('poll');
- }
-
- if(isset($CNF['PARAM_MULTICAT_ENABLED']) && $CNF['PARAM_MULTICAT_ENABLED'] === true) {
- $sInclude2 = '';
- $sInclude2 .= $this->_oModule->_oTemplate->addJs(array('categories.js'), $bDynamicMode);
- $sInclude2 .= $this->_oModule->_oTemplate->addCss(array('categories.css'), $bDynamicMode);
-
- $sResult .= ($bDynamicMode ? $sInclude2 : '') . $this->_oModule->_oTemplate->getJsCode('categories');
- }
- return $sResult;
- }
- function initChecker ($aValues = array (), $aSpecificValues = array())
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- $bValues = $aValues && !empty($aValues['id']);
- $aContentInfo = $bValues ? $this->_oModule->_oDb->getContentInfoById($aValues['id']) : false;
- if (isset($CNF['FIELD_VIDEO']) && isset($this->aInputs[$CNF['FIELD_VIDEO']])) {
- if ($bValues)
- $this->aInputs[$CNF['FIELD_VIDEO']]['content_id'] = $aValues['id'];
- $this->aInputs[$CNF['FIELD_VIDEO']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateVideo, $this->_getVideoGhostTmplVars($aContentInfo));
- }
- if (isset($CNF['FIELD_FILE']) && isset($this->aInputs[$CNF['FIELD_FILE']])) {
- if ($bValues)
- $this->aInputs[$CNF['FIELD_FILE']]['content_id'] = $aValues['id'];
- $this->aInputs[$CNF['FIELD_FILE']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateFile, $this->_getFileGhostTmplVars($aContentInfo));
- }
- if (isset($CNF['FIELD_POLL']) && isset($this->aInputs[$CNF['FIELD_POLL']])) {
- if ($bValues)
- $this->aInputs[$CNF['FIELD_POLL']]['content_id'] = $aValues['id'];
- }
-
- if (isset($CNF['FIELD_MULTICAT']) && isset($this->aInputs[$CNF['FIELD_MULTICAT']]) && $CNF['PARAM_MULTICAT_ENABLED']) {
- if ($bValues)
- $this->aInputs[$CNF['FIELD_MULTICAT']]['content_id'] = $aValues['id'];
- }
- parent::initChecker ($aValues, $aSpecificValues);
- }
- protected function genCustomInputAttachments ($aInput)
- {
- return '__attachments_menu__';
- }
- protected function genCustomInputPolls ($aInput)
- {
- return $this->_oModule->_oTemplate->getPollField(!empty($aInput['content_id']) ? (int)$aInput['content_id'] : 0);
- }
- public function processPolls ($sFieldPoll, $iContentId = 0)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if (!isset($this->aInputs[$sFieldPoll]))
- return true;
- $aPollIds = $this->getCleanValue($sFieldPoll);
- if(empty($aPollIds) || !is_array($aPollIds))
- return true;
- $iProfileId = $this->getContentOwnerProfileId($iContentId);
- $aPollsDbIds = $this->_oModule->_oDb->getPolls(array('type' => 'content_id_ids', 'content_id' => $iContentId));
- //--- Remove deleted
- $this->_oModule->_oDb->deletePollsByIds(array_diff($aPollsDbIds, $aPollIds));
- //--- Add new
- if($iContentId) {
- $aPollsAddIds = array_diff($aPollIds, $aPollsDbIds);
- foreach($aPollsAddIds as $iPollId)
- $this->_oModule->_oDb->updatePolls(array($CNF['FIELD_POLL_CONTENT_ID'] => $iContentId), array($CNF['FIELD_POLL_ID'] => $iPollId, $CNF['FIELD_POLL_CONTENT_ID'] => 0));
- }
- return true;
- }
-
- /**
- *
- * MultiCategories related methods.
- *
- */
-
- protected function processMulticatBefore($sFieldName, &$aValsToAdd){
- if (isset($this->aInputs[$sFieldName])){
- $this->aInputs[$sFieldName]['value'] = array_unique(array_filter($this->aInputs[$sFieldName]['value'], function($sTmp){
- return trim($sTmp);
- }));
- $aValsToAdd[$sFieldName] = implode(',', $this->aInputs[$sFieldName]['value']);
- }
- }
-
- protected function processMulticatAfter($sFieldName, $iContentId){
- $bAutoActivation = (isset($CNF['PARAM_MULTICAT_AUTO_ACTIVATION_FOR_CATEGORIES']) && getParam($CNF['PARAM_MULTICAT_AUTO_ACTIVATION_FOR_CATEGORIES']) == 'on') ? true : false;
- $oCategories = BxDolCategories::getInstance();
- if (isset($this->aInputs[$sFieldName])){
- $oCategories->delete($this->_oModule->getName(), $iContentId);
- foreach($this->aInputs[$sFieldName]['value'] as $sValue) {
- $oCategories->add($this->_oModule->getName(), bx_get_logged_profile_id(), $sValue, $iContentId, $bAutoActivation);
- }
- }
- }
-
- protected function genCustomViewRowValueMulticat(&$aInput)
- {
- $oCategories = BxDolCategories::getInstance();
- $aValues = $oCategories->getData(array('type' => 'by_module_and_object', 'module' => $this->_oModule->getName(), 'object_id' => (!empty($aInput['content_id']) ? (int)$aInput['content_id'] : 0 )));
- if (count($aValues) > 0){
- $aVars = array('bx_repeat:cats' => array());
- foreach ($aValues as $sValue) {
- $aVars['bx_repeat:cats'][] = array(
- 'url' => $oCategories->getUrl($this->_oModule->getName(), $sValue),
- 'name' => $sValue,
- 'bx_if:more' => array(
- 'condition' => $sValue === end($aValues) ? false : true,
- 'content' => array('1')
- ),
- );
- }
-
- if (!$aVars['bx_repeat:cats'])
- return '';
- return $this->_oModule->_oTemplate->parseHtmlByName('category_list_inline.html', $aVars);
- }
- return '';
- }
-
- protected function genCustomInputMulticat(&$aInput)
- {
- $sJsObject = $this->_oModule->_oConfig->getJsObject('categories');
- $aValuesForSelect = BxDolCategories::getInstance()->getData(array('type' => 'by_module_and_author', 'module' => $this->_oModule->getName(), 'author' => bx_get_logged_profile_id()));
-
- $aSelectedItems = array();
- if(!empty($aInput['value'])) {
- if (!is_array($aInput['value']))
- $aValues = BxDolCategories::getInstance()->getData(array('type' => 'by_module_and_object', 'module' => $this->_oModule->getName(), 'object_id' => (!empty($aInput['content_id']) ? (int)$aInput['content_id'] : 0 )));
- else
- $aValues = $aInput['value'];
-
- $aValues = array_filter($aValues);
- foreach($aValues as $sValue) {
- if (!array_key_exists($sValue, $aValuesForSelect)){
- $aValuesForSelect[$sValue] = array('key' => $sValue, 'value' => $sValue);
- }
- }
- foreach($aValues as $sValue) {
- $sInput = $this->genCustomInputMulticatSelect($aInput, $aValuesForSelect, $sValue);
- $aSelectedItems[] = array('js_object' => $sJsObject, 'select_cat' => $sInput);
- }
- }
- else{
- $aSelectedItems = array();
- }
- return $this->_oModule->_oTemplate->parseHtmlByName('form_categories.html', array(
- 'bx_repeat:items' => $aSelectedItems,
- 'js_object' => $sJsObject,
- 'select_cat' => $this->genCustomInputMulticatSelect($aInput, $aValuesForSelect, -1),
- 'input_cat' => $this->genCustomInputMulticatInput($aInput),
- 'js_object' => $sJsObject,
- 'btn_add' => $this->genCustomInputMulticatButton($aInput),
- 'btn_add_new' => $this->genCustomInputMulticatButtonNew($aInput)
- ));
- }
-
- protected function genCustomInputMulticatSelect($aInput, $aValues, $mixedValue = '')
- {
- foreach($aValues as $sKey => $aValue) {
- $aValues[$sKey]['value'] = _t($aValue['key']);
- }
- $aValues = array_merge(array('1' => array('key' => false, 'value' => _t('_sys_please_select'))), $aValues);
-
- $aInput['type'] = 'select';
- $aInput['name'] .= '[]';
- $aInput['value'] = $mixedValue;
- $aInput['values'] = $aValues;
- return $this->genInput($aInput);
- }
-
- protected function genCustomInputMulticatInput($aInput)
- {
- $aInput['type'] = 'text';
- $aInput['name'] .= '[]';
- $aInput['value'] = '';
- return $this->genInput($aInput);
- }
-
- protected function genCustomInputMulticatButton($aInput)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- $sName = $aInput['name'];
- $aInput['type'] = 'button';
- $aInput['name'] .= '_add';
- $aInput['value'] = _t($CNF['T']['txt_multicat_button_caption_add']);
- $aInput['attrs']['class'] = 'bx-def-margin-right bx-def-margin-sec-top';
- $aInput['attrs']['onclick'] = $this->_oModule->_oConfig->getJsObject('categories') . ".categoryAdd(this, '" . $sName . "');";
- return $this->genInputButton($aInput);
- }
-
- protected function genCustomInputMulticatButtonNew($aInput)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- $sName = $aInput['name'];
- $aInput['type'] = 'button';
- $aInput['name'] .= '_add';
- $aInput['value'] = _t($CNF['T']['txt_multicat_button_caption_addnew']);
- $aInput['attrs']['class'] = 'bx-def-margin-sec-top';
- $aInput['attrs']['onclick'] = $this->_oModule->_oConfig->getJsObject('categories') . ".categoryAddNew(this, '" . $sName . "');";
- return $this->genInputButton($aInput);
- }
- protected function _getVideoGhostTmplVars($aContentInfo = array())
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- return array (
- 'name' => $this->aInputs[$CNF['FIELD_VIDEO']]['name'],
- 'content_id' => (int)$this->aInputs[$CNF['FIELD_VIDEO']]['content_id'],
- 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '',
- 'embed_url' => BX_DOL_URL_ROOT . $this->_oModule->_oConfig->getBaseUri() . 'file_embed_video/',
- );
- }
- protected function _getFileGhostTmplVars($aContentInfo = array())
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- return array (
- 'name' => $this->aInputs[$CNF['FIELD_FILE']]['name'],
- 'content_id' => (int)$this->aInputs[$CNF['FIELD_FILE']]['content_id'],
- 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : ''
- );
- }
- }
- /** @} */
|