Przeglądaj źródła

Ticket #5273 - Get rid of duplicates in code.

AntonLV 11 miesięcy temu
rodzic
commit
566b00a0e0

+ 12 - 44
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -3876,46 +3876,16 @@ class BxBaseModGeneralModule extends BxDolModule
     }
 
     public function processMetasAdd($iContentId)
-    {
-        $CNF = &$this->_oConfig->CNF;
-
-        if(empty($CNF['OBJECT_METATAGS'])) 
-            return false;
-
-        $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
-
-        $bFldStatus = !empty($CNF['FIELD_STATUS']);
-        $bFldStatusAdmin = !empty($CNF['FIELD_STATUS_ADMIN']);
-        $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
-        if(!$bContentInfo)
-            return false;
-
-        $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
-        $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']);
-
-        $sKey = 'FIELD_LOCATION';
-        if($oMetatags->locationsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
-            $aLocation = unserialize($aContentInfo[$CNF[$sKey]]);
-            if(!empty($aLocation) && is_array($aLocation))
-                call_user_func_array(array($oMetatags, 'locationsAdd'), array_merge(array($iContentId), array_values($aLocation)));
-        }
-
-        $sKey = 'FIELD_LABELS';
-        if($oMetatags->keywordsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
-            $aLabels = unserialize($aContentInfo[$CNF[$sKey]]);
-            if(!empty($aLabels) && is_array($aLabels))
-                foreach ($aLabels as $sLabel) {
-                    if(!preg_match("/(\pL[\pL\pN_]+)/u", $sLabel)) 
-                        continue;
-
-                    $oMetatags->keywordsAddOne($iContentId, $sLabel, false);
-                }
-        }
-        
-        return true;
+    {        
+        return $this->processMetas('add', $iContentId);
     }
 
     public function processMetasEdit($iContentId, $oForm)
+    {
+        return $this->processMetas('edit', $iContentId, $oForm);
+    }
+
+    public function processMetas($aAction, $iContentId, $oForm = false)
     {
         $CNF = &$this->_oConfig->CNF;
 
@@ -3924,24 +3894,22 @@ class BxBaseModGeneralModule extends BxDolModule
 
         $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
 
-        $bFldStatus = isset($CNF['FIELD_STATUS']);
-        $bFldStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']);
+        $bFldStatus = !empty($CNF['FIELD_STATUS']);
+        $bFldStatusAdmin = !empty($CNF['FIELD_STATUS_ADMIN']);
         $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
         if(!$bContentInfo)
             return false;
 
         $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
-        $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT']);
+        $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_' . strtoupper($aAction)]);
 
-        $sKey = 'FIELD_LOCATION';
-        if($oMetatags->locationsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
+        if($oMetatags->locationsIsEnabled() && ($sKey = 'FIELD_LOCATION') && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
             $aLocation = unserialize($aContentInfo[$CNF[$sKey]]);
             if(!empty($aLocation) && is_array($aLocation))
                 call_user_func_array(array($oMetatags, 'locationsAdd'), array_merge(array($iContentId), array_values($aLocation)));
         }
 
-        $sKey = 'FIELD_LABELS';
-        if($oMetatags->keywordsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
+        if($oMetatags->keywordsIsEnabled() && ($sKey = 'FIELD_LABELS') && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
             $aLabels = unserialize($aContentInfo[$CNF[$sKey]]);
             if(!empty($aLabels) && is_array($aLabels))
                 foreach ($aLabels as $sLabel) {

+ 5 - 106
modules/boonex/invites/classes/BxInvGridInvites.php

@@ -8,26 +8,18 @@
  * 
  * @{
  */
+
+require_once('BxInvGrid.php');
+
 define('BX_INV_FILTER_STATUS_ACCEPTED', 1);
 define('BX_INV_FILTER_STATUS_NOT_ACCEPTED', 2);
 
-class BxInvGridInvites extends BxTemplGrid
-{
-    protected $_sModule;
-    protected $_oModule;
-
-    protected $_sFilter1Name;
-    protected $_sFilter1Value;
-    protected $_aFilter1Values;
-    protected $_sParamsDivider;
-    
+class BxInvGridInvites extends BxInvGrid
+{    
     public function __construct ($aOptions, $oTemplate = false)
     {
         parent::__construct ($aOptions, $oTemplate);
 
-        $this->_sModule = 'bx_invites';
-        $this->_oModule = BxDolModule::getInstance($this->_sModule);
-
         $this->_sDefaultSortingOrder = 'DESC';
 
         $this->_sFilter1Name = 'filter1';
@@ -42,50 +34,6 @@ class BxInvGridInvites extends BxTemplGrid
             $this->_sFilter1Value = bx_process_input($sFilter1);
             $this->_aQueryAppend['filter1'] = $this->_sFilter1Value;
         }
-        $this->_sParamsDivider = '#-#';
-    }
-
-    public function getFormCallBackUrlAPI($sAction, $iId = 0)
-    {
-         return '/api.php?r=system/perfom_action_api/TemplServiceGrid/&params[]=&o=' . $this->_sObject . '&a=' . $sAction;
-    }
-    
-    public function performActionAdd()
-    {
-        $sAction = 'add';
-
-        $oForm = $this->_oModule->getFormObjectInvite();
-        if(!$oForm)
-            return $this->_getActionResult([]);
-
-        $oForm->aInputs['text']['value'] = _t('_bx_invites_msg_invitation');
-        $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?' . bx_encode_url_params($_GET, array('ids', '_r'));
-        $oForm->initChecker();
-
-        $aResult = [];
-        if($oForm->isSubmittedAndValid()) {
-            $sResult = $this->_oModule->processFormObjectInvite($oForm);
-            if($this->_bIsApi)
-                $aResult = [bx_api_get_msg($sResult)];
-            else
-                $aResult = ['msg' => $sResult];
-        }
-        else {
-            if($this->_bIsApi)
-                $aResult = $this->getFormBlockAPI($oForm, $sAction);
-            else
-                $aResult = ['popup' => [
-                    'html' => BxTemplFunctions::getInstance()->popupBox('_bx_invites_form_invite', _t('_bx_invites_form_invite'), $this->_oModule->_oTemplate->parseHtmlByName('popup_invite.html', array(
-                        'form_id' => $oForm->id,
-                        'form' => $oForm->getCode(true),
-                        'object' => $this->_sObject,
-                        'action' => $sAction
-                    ))), 
-                    'options' => ['closeOnOuterClick' => true]
-                ]];
-        }
-
-        return $this->_getActionResult($aResult);
     }
     
     public function performActionDelete($aParams = array())
@@ -118,55 +66,6 @@ class BxInvGridInvites extends BxTemplGrid
 
         echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_bx_invites_err_delete_invite')));
     }
-    
-    protected function _getFilterControls ()
-    {
-        parent::_getFilterControls();
-        return  $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values) . $this->_getSearchInput();
-    }
-    
-    protected function _getSearchInput()
-    {
-        $sJsObject = $this->_oModule->_oConfig->getJsObject('main');
-        $aInputSearch = array(
-            'type' => 'text',
-            'name' => 'search',
-            'attrs' => array(
-                'id' => 'bx-grid-search-' . $this->_sObject,
-                'onKeyup' => 'javascript:$(this).off(\'keyup focusout\'); ' . $sJsObject . '.onChangeFilter(this)',
-                'onBlur' => 'javascript:' . $sJsObject . '.onChangeFilter(this)',
-            )
-        );
-
-        $oForm = new BxTemplFormView(array());
-        return $oForm->genRow($aInputSearch);
-    }
-    
-    protected function _getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues)
-    {
-        if(empty($sFilterName) || empty($aFilterValues))
-            return '';
-
-        $CNF = &$this->_oModule->_oConfig->CNF;
-        $sJsObject = $this->_oModule->_oConfig->getJsObject('main');
-
-        foreach($aFilterValues as $sKey => $sValue)
-            $aFilterValues[$sKey] = _t($sValue);
-
-        $aInputModules = array(
-            'type' => 'select',
-            'name' => $sFilterName,
-            'attrs' => array(
-                'id' => 'bx-grid-' . $sFilterName . '-' . $this->_sObject,
-                'onChange' => 'javascript:' . $sJsObject . '.onChangeFilter(this)'
-            ),
-            'value' => $sFilterValue,
-            'values' => $aFilterValues
-        );
-
-        $oForm = new BxTemplFormView(array());
-        return $oForm->genRow($aInputModules);
-    }
 
     protected function _getCellEmail($mixedValue, $sKey, $aField, $aRow)
     {

+ 4 - 138
modules/boonex/invites/classes/BxInvGridRequests.php

@@ -9,30 +9,21 @@
  * @{
  */
 
+require_once('BxInvGrid.php');
+
 define('BX_INV_FILTER_STATUS_NEW', 0);
 define('BX_INV_FILTER_STATUS_INVITED', 1);
 define('BX_INV_FILTER_STATUS_SEEN', 2);
 define('BX_INV_FILTER_STATUS_JOINED', 3);
 
-class BxInvGridRequests extends BxTemplGrid
-{
-    protected $_sModule;
-    protected $_oModule;
-
-    protected $_sFilter1Name;
-    protected $_sFilter1Value;
-    protected $_aFilter1Values;
-    protected $_sParamsDivider;
-    
+class BxInvGridRequests extends BxInvGrid
+{    
     public function __construct ($aOptions, $oTemplate = false)
     {
         parent::__construct ($aOptions, $oTemplate);
 
         $this->_aQueryReset = array('order_field', 'order_dir', $this->_aOptions['paginate_get_start'], $this->_aOptions['paginate_get_per_page']);
         
-        $this->_sModule = 'bx_invites';
-        $this->_oModule = BxDolModule::getInstance($this->_sModule);
-        
         $this->_sFilter1Name = 'filter1';
         $this->_aFilter1Values = array(
             '' => _t('_bx_invites_request_status_for_filter_all'),
@@ -47,50 +38,6 @@ class BxInvGridRequests extends BxTemplGrid
             $this->_sFilter1Value = bx_process_input($sFilter1);
             $this->_aQueryAppend['filter1'] = $this->_sFilter1Value;
         }
-        $this->_sParamsDivider = '#-#';
-    }
-
-    public function getFormCallBackUrlAPI($sAction, $iId = 0)
-    {
-         return '/api.php?r=system/perfom_action_api/TemplServiceGrid/&params[]=&o=' . $this->_sObject . '&a=' . $sAction;
-    }
-
-    public function performActionAdd()
-    {
-        $sAction = 'add';
-
-        $oForm = $this->_oModule->getFormObjectInvite();
-        if(!$oForm)
-            return $this->_getActionResult([]);
-
-        $oForm->aInputs['text']['value'] = _t('_bx_invites_msg_invitation');
-        $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?' . bx_encode_url_params($_GET, array('ids', '_r'));
-        $oForm->initChecker();
-
-        $aResult = [];
-        if($oForm->isSubmittedAndValid()) {
-            $sResult = $this->_oModule->processFormObjectInvite($oForm);
-            if($this->_bIsApi)
-                $aResult = [bx_api_get_msg($sResult)];
-            else
-                $aResult = ['msg' => $sResult];
-        }
-        else {
-            if($this->_bIsApi)
-                $aResult = $this->getFormBlockAPI($oForm, $sAction);
-            else
-                $aResult = ['popup' => [
-                    'html' => BxTemplFunctions::getInstance()->popupBox('_bx_invites_form_invite', _t('_bx_invites_form_invite'), $this->_oModule->_oTemplate->parseHtmlByName('popup_invite.html', [
-                        'form_id' => $oForm->id,
-                        'form' => $oForm->getCode(true),
-                        'object' => $this->_sObject,
-                        'action' => $sAction
-                    ])), 
-                    'options' => ['closeOnOuterClick' => true]
-                ]];
-        }
-
-        return $this->_getActionResult($aResult);
     }
     
     public function performActionInfo()
@@ -215,55 +162,6 @@ class BxInvGridRequests extends BxTemplGrid
         return $this->_getActionResult($aResult);
     }
 
-    protected function _getFilterControls ()
-    {
-        parent::_getFilterControls();
-        return  $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values) . $this->_getSearchInput();
-    }
-
-    protected function _getSearchInput()
-    {
-        $sJsObject = $this->_oModule->_oConfig->getJsObject('main');
-        $aInputSearch = array(
-            'type' => 'text',
-            'name' => 'search',
-            'attrs' => array(
-                'id' => 'bx-grid-search-' . $this->_sObject,
-                'onKeyup' => 'javascript:$(this).off(\'keyup focusout\'); ' . $sJsObject . '.onChangeFilter(this)',
-                'onBlur' => 'javascript:' . $sJsObject . '.onChangeFilter(this)',
-            )
-        );
-
-        $oForm = new BxTemplFormView(array());
-        return $oForm->genRow($aInputSearch);
-    }
-    
-    protected function _getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues)
-    {
-        if(empty($sFilterName) || empty($aFilterValues))
-            return '';
-
-        $CNF = &$this->_oModule->_oConfig->CNF;
-        $sJsObject = $this->_oModule->_oConfig->getJsObject('main');
-
-        foreach($aFilterValues as $sKey => $sValue)
-            $aFilterValues[$sKey] = _t($sValue);
-
-        $aInputModules = array(
-            'type' => 'select',
-            'name' => $sFilterName,
-            'attrs' => array(
-                'id' => 'bx-grid-' . $sFilterName . '-' . $this->_sObject,
-                'onChange' => 'javascript:' . $sJsObject . '.onChangeFilter(this)'
-            ),
-            'value' => $sFilterValue,
-            'values' => $aFilterValues
-        );
-
-        $oForm = new BxTemplFormView(array());
-        return $oForm->genRow($aInputModules);
-    }
-
     protected function _getCellNip($mixedValue, $sKey, $aField, $aRow)
     {
         return parent::_getCellDefault(long2ip($mixedValue), $sKey, $aField, $aRow);
@@ -361,38 +259,6 @@ class BxInvGridRequests extends BxTemplGrid
     {
         return " ORDER BY `status` ASC, `date` DESC";
     }
-
-    protected function _getId()
-    {
-        $iId = 0;
-
-        if(($aIds = bx_get('ids')) !== false) {
-            if(!$aIds || !is_array($aIds))
-                return 0;
-
-            $iId = (int)array_shift($aIds);
-        }
-        else if(($iId = bx_get('id')) !== false)
-            $iId = (int)$iId;
-        
-        return $iId;
-    }
-
-    protected function _getIds()
-    {
-        $aIds = [];
-
-        if(($aIds = bx_get('ids')) !== false) {
-            if(!$aIds || !is_array($aIds))
-                return [];
-
-            $aIds = bx_process_input($aIds, BX_DATA_INT);
-        }
-        else if(($iId = bx_get('id')) !== false)
-            $aIds = [(int)$iId];
-
-        return $aIds;
-    }
 }
 
 /** @} */

+ 2 - 29
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -2689,36 +2689,9 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
      */
     public function serviceGetNotificationsReply($aEvent)
     {
-        $CNF = &$this->_oConfig->CNF;
-
-        $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], 0, false);
-        if(!$oComment || !$oComment->isEnabled())
-            return [];
-
-        $iParentId = (int)$aEvent['object_id'];
-        $aParentInfo = $oComment->getQueryObject()->getCommentsBy(array('type' => 'id', 'id' => $iParentId));
-        if(empty($aParentInfo) || !is_array($aParentInfo))
-            return [];
-
-        $iObjectId = (int)$aParentInfo['cmt_object_id'];
-        $oComment->init($iObjectId);
-        $iCommentId = (int)$aEvent['subobject_id'];
-
-        return [
-            'object_id' => $iObjectId,
-            'entry_sample' => '_cmt_txt_sample_comment_single',
-            'entry_url' => $oComment->getItemUrl($iParentId, '{bx_url_root}'),
-            'entry_url_api' => $oComment->getItemUrlApi($iParentId, '{bx_url_root}'),
-            'entry_caption' => strmaxtextlen($aParentInfo['cmt_text'], 20, '...'),
-            'entry_summary' => $oComment->getViewText($iParentId),
-            'entry_author' => (int)$aParentInfo['cmt_author_id'],
-            'subentry_sample' => '_cmt_txt_sample_reply_to',
-            'subentry_url' => $oComment->getItemUrl($iCommentId, '{bx_url_root}'),
-            'subentry_url_api' => $oComment->getItemUrlApi($iCommentId, '{bx_url_root}'),
-            'subentry_summary' => $oComment->getViewText($iCommentId),
-            'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
+        return array_merge(parent::serviceGetNotificationsReply($aEvent), [
             'modal_view' => $this->getName()
-        ];
+        ]);
     }
 
     /**