Просмотр исходного кода

Ticket #5273 - Get rid of duplicates in code.

AntonLV 11 месяцев назад
Родитель
Сommit
9fd3a14c7a

+ 106 - 14
modules/base/text/classes/BxBaseModTextFormEntry.php

@@ -128,7 +128,7 @@ class BxBaseModTextFormEntry extends BxBaseModGeneralFormEntry
     	return $sResult;
     }
 
-    function initChecker ($aValues = array (), $aSpecificValues = array())
+    function initChecker ($aValues = [], $aSpecificValues = [])
     {
         $CNF = &$this->_oModule->_oConfig->CNF;
 
@@ -136,7 +136,18 @@ class BxBaseModTextFormEntry extends BxBaseModGeneralFormEntry
         $iValueId = $bValues ? (int)$aValues['id'] : 0;
         $iUserId = $this->_oModule->getUserId();
         $aContentInfo = $bValues ? $this->_oModule->_oDb->getContentInfoById($aValues['id']) : false;
-            
+
+        if($this->aParams['display'] == $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'] && isset($CNF['FIELD_PUBLISHED']) && isset($this->aInputs[$CNF['FIELD_PUBLISHED']]))
+            if($bValues && in_array($aValues[$CNF['FIELD_STATUS']], ['active', 'hidden']))
+                unset($this->aInputs[$CNF['FIELD_PUBLISHED']]);
+
+        if (isset($CNF['FIELD_COVER']) && isset($this->aInputs[$CNF['FIELD_COVER']])) {
+            if($bValues)
+                $this->aInputs[$CNF['FIELD_COVER']]['content_id'] = $aValues['id'];
+
+            $this->aInputs[$CNF['FIELD_COVER']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateCover, $this->_getCoverGhostTmplVars($aContentInfo));
+        }
+
         if (isset($CNF['FIELD_VIDEO']) && isset($this->aInputs[$CNF['FIELD_VIDEO']])) {
             if ($bValues)
                 $this->aInputs[$CNF['FIELD_VIDEO']]['content_id'] = $aValues['id'];
@@ -168,9 +179,63 @@ class BxBaseModTextFormEntry extends BxBaseModGeneralFormEntry
         }
     }
 
-    function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
+    public function insert ($aValsToAdd = [], $isIgnore = false)
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        if(isset($CNF['FIELD_ADDED']) && empty($aValsToAdd[$CNF['FIELD_ADDED']])) {
+            $iAdded = 0;
+            if(isset($this->aInputs[$CNF['FIELD_ADDED']]))
+                $iAdded = $this->getCleanValue($CNF['FIELD_ADDED']);
+
+            if(empty($iAdded))
+                 $iAdded = time();
+
+            $aValsToAdd[$CNF['FIELD_ADDED']] = $iAdded;
+        }
+
+        if(isset($CNF['FIELD_PUBLISHED'])) {
+            if(empty($aValsToAdd[$CNF['FIELD_PUBLISHED']])) {
+                $iPublished = 0;
+                if(isset($this->aInputs[$CNF['FIELD_PUBLISHED']]))
+                    $iPublished = $this->getCleanValue($CNF['FIELD_PUBLISHED']);
+
+                 if(empty($iPublished))
+                     $iPublished = time();
+
+                 $aValsToAdd[$CNF['FIELD_PUBLISHED']] = $iPublished;
+            }
+
+            if(empty($aValsToAdd[$CNF['FIELD_STATUS']]))
+                $aValsToAdd[$CNF['FIELD_STATUS']] = $aValsToAdd[$CNF['FIELD_PUBLISHED']] > $aValsToAdd[$CNF['FIELD_ADDED']] ? 'awaiting' : 'active';
+        }
+        
+        $iContentId = parent::insert ($aValsToAdd, $isIgnore);
+
+        if(isset($CNF['FIELD_COVER']) && !empty($iContentId))
+            $this->processFiles($CNF['FIELD_COVER'], $iContentId, true);
+
+        return $iContentId;
+    }
+
+    public function update ($iContentId, $aValsToAdd = [], &$aTrackTextFieldsChanges = null)
     {
-       return parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        if(isset($CNF['FIELD_PUBLISHED']) && empty($aValsToAdd[$CNF['FIELD_PUBLISHED']]) && isset($this->aInputs[$CNF['FIELD_PUBLISHED']])) {
+            $iPublished = $this->getCleanValue($CNF['FIELD_PUBLISHED']);
+            if(empty($iPublished))
+                $iPublished = time();
+
+            $aValsToAdd[$CNF['FIELD_PUBLISHED']] = $iPublished;
+        }
+
+        $iResult = parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
+
+        if(isset($CNF['FIELD_COVER']))
+            $this->processFiles($CNF['FIELD_COVER'], $iContentId, false);   
+
+        return $iResult;
     }
     
     protected function genCustomInputAttachments ($aInput)
@@ -191,41 +256,68 @@ class BxBaseModTextFormEntry extends BxBaseModGeneralFormEntry
         foreach($aLinkIds as $iLinkId)
             $this->_oModule->_oDb->saveLink($iContentId, $iLinkId);
     }
-    
 
-    protected function _getVideoGhostTmplVars($aContentInfo = array())
+    protected function _getCoverGhostTmplVars($aContentInfo = [])
+    {
+    	$CNF = &$this->_oModule->_oConfig->CNF;
+
+    	return [
+            'name' => $this->aInputs[$CNF['FIELD_COVER']]['name'],
+            'content_id' => $this->aInputs[$CNF['FIELD_COVER']]['content_id'],
+            'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '',
+            'thumb_id' => isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) ? $aContentInfo[$CNF['FIELD_THUMB']] : 0,
+            'name_thumb' => isset($CNF['FIELD_THUMB']) ? $CNF['FIELD_THUMB'] : ''
+        ];
+    }
+
+    protected function _getPhotoGhostTmplVars($aContentInfo = [])
+    {
+    	$CNF = &$this->_oModule->_oConfig->CNF;
+
+    	return [
+            'name' => $this->aInputs[$CNF['FIELD_PHOTO']]['name'],
+            'content_id' => (int)$this->aInputs[$CNF['FIELD_PHOTO']]['content_id'],
+            'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '',
+            'bx_if:set_thumb' => [
+                'condition' => false,
+                'content' => []
+            ],
+    	];
+    }
+
+    protected function _getVideoGhostTmplVars($aContentInfo = [])
     {
     	$CNF = &$this->_oModule->_oConfig->CNF;
 
-    	return array (
+    	return [
             '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 _getSoundGhostTmplVars($aContentInfo = array())
+    protected function _getSoundGhostTmplVars($aContentInfo = [])
     {
     	$CNF = &$this->_oModule->_oConfig->CNF;
 
-    	return array (
+    	return [
             'name' => $this->aInputs[$CNF['FIELD_SOUND']]['name'],
             'content_id' => (int)$this->aInputs[$CNF['FIELD_SOUND']]['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_sound/',
-    	);
+    	];
     }
 
-    protected function _getFileGhostTmplVars($aContentInfo = array())
+    protected function _getFileGhostTmplVars($aContentInfo = [])
     {
     	$CNF = &$this->_oModule->_oConfig->CNF;
 
-    	return array (
+    	return [
             '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'] : ''
-    	);
+    	];
     }
 }
 

+ 3 - 87
modules/boonex/classes/classes/BxClssFormEntry.php

@@ -31,17 +31,6 @@ class BxClssFormEntry extends BxBaseModTextFormEntry
         $bValues = $aValues && !empty($aValues['id']);
         $aContentInfo = $bValues ? $this->_oModule->_oDb->getContentInfoById($aValues['id']) : false;
 
-        if($this->aParams['display'] == $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'] && isset($CNF['FIELD_PUBLISHED']) && isset($this->aInputs[$CNF['FIELD_PUBLISHED']]))
-            if($bValues && in_array($aValues[$CNF['FIELD_STATUS']], array('active', 'hidden')))
-                unset($this->aInputs[$CNF['FIELD_PUBLISHED']]);
-
-        if (isset($CNF['FIELD_COVER']) && isset($this->aInputs[$CNF['FIELD_COVER']])) {
-            if($bValues)
-                $this->aInputs[$CNF['FIELD_COVER']]['content_id'] = $aValues['id'];
-
-            $this->aInputs[$CNF['FIELD_COVER']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateCover, $this->_getCoverGhostTmplVars($aContentInfo));
-        }
-
         parent::initChecker ($aValues, $aSpecificValues);
 
         // try to get context from form POST
@@ -74,89 +63,16 @@ class BxClssFormEntry extends BxBaseModTextFormEntry
         }
     }
 
-    public function insert ($aValsToAdd = array(), $isIgnore = false)
+    public function insert ($aValsToAdd = [], $isIgnore = false)
     {
         $CNF = &$this->_oModule->_oConfig->CNF;
 
-        if(isset($CNF['FIELD_ADDED']) && empty($aValsToAdd[$CNF['FIELD_ADDED']])) {
-            $iAdded = 0;
-            if(isset($this->aInputs[$CNF['FIELD_ADDED']]))
-                $iAdded = $this->getCleanValue($CNF['FIELD_ADDED']);
-            
-            if(empty($iAdded))
-                 $iAdded = time();
-
-            $aValsToAdd[$CNF['FIELD_ADDED']] = $iAdded;
-        }
-
-        if(empty($aValsToAdd[$CNF['FIELD_PUBLISHED']])) {
-            $iPublished = 0;
-            if(isset($this->aInputs[$CNF['FIELD_PUBLISHED']]))
-                $iPublished = $this->getCleanValue($CNF['FIELD_PUBLISHED']);
-                
-             if(empty($iPublished))
-                 $iPublished = time();
-
-             $aValsToAdd[$CNF['FIELD_PUBLISHED']] = $iPublished;
-        }
-
-        $aValsToAdd[$CNF['FIELD_STATUS']] = $aValsToAdd[$CNF['FIELD_PUBLISHED']] > $aValsToAdd[$CNF['FIELD_ADDED']] ? 'awaiting' : 'active';
-
         $aValsToAdd['order'] = $this->_oModule->_oDb->getClassMaxOrder(abs($this->getCleanValue($CNF['FIELD_ALLOW_VIEW_TO'])), $this->getCleanValue($CNF['FIELD_MODULE']));
 
-        $iContentId = parent::insert ($aValsToAdd, $isIgnore);
-        if(!empty($iContentId)){
-            $this->processFiles($CNF['FIELD_COVER'], $iContentId, true);
-        }
-        return $iContentId;
-    }
-
-    function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
-    {
-        $CNF = &$this->_oModule->_oConfig->CNF;
-
-        if(empty($aValsToAdd[$CNF['FIELD_PUBLISHED']]) && isset($this->aInputs[$CNF['FIELD_PUBLISHED']])) {
-            $iPublished = $this->getCleanValue($CNF['FIELD_PUBLISHED']);
-            if(empty($iPublished))
-                $iPublished = time();
-
-            $aValsToAdd[$CNF['FIELD_PUBLISHED']] = $iPublished;
-        }
-        
-        $iResult = parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
-        $this->processFiles($CNF['FIELD_COVER'], $iContentId, false);   
-        return $iResult;
-    }
-
-    protected function _getCoverGhostTmplVars($aContentInfo = array())
-    {
-    	$CNF = &$this->_oModule->_oConfig->CNF;
-
-    	return array (
-            'name' => $this->aInputs[$CNF['FIELD_COVER']]['name'],
-            'content_id' => $this->aInputs[$CNF['FIELD_COVER']]['content_id'],
-            'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '',
-            'thumb_id' => isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) ? $aContentInfo[$CNF['FIELD_THUMB']] : 0,
-            'name_thumb' => isset($CNF['FIELD_THUMB']) ? $CNF['FIELD_THUMB'] : ''
-        );
-    }
-
-    protected function _getPhotoGhostTmplVars($aContentInfo = array())
-    {
-    	$CNF = &$this->_oModule->_oConfig->CNF;
-
-    	return array (
-            'name' => $this->aInputs[$CNF['FIELD_PHOTO']]['name'],
-            'content_id' => (int)$this->aInputs[$CNF['FIELD_PHOTO']]['content_id'],
-            'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '',
-            'bx_if:set_thumb' => [
-				'condition' => false,
-				'content' => []
-			],
-    	);
+        return parent::insert ($aValsToAdd, $isIgnore);
     }
 
-    function getCode($bDynamicMode = false)
+    public function getCode($bDynamicMode = false)
     {
         if (!$this->_bViewMode) {
             if (!$this->_oProfileContext)

+ 7 - 58
modules/boonex/forum/classes/BxForumFormEntry.php

@@ -23,38 +23,17 @@ class BxForumFormEntry extends BxBaseModTextFormEntry
         parent::__construct($aInfo, $oTemplate);
     }
 
-    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_COVER']) && isset($this->aInputs[$CNF['FIELD_COVER']])) {
-            if($bValues)
-                $this->aInputs[$CNF['FIELD_COVER']]['content_id'] = $aValues['id'];
-
-            $this->aInputs[$CNF['FIELD_COVER']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateCover, $this->_getCoverGhostTmplVars($aContentInfo));
-        }
-
-        parent::initChecker ($aValues, $aSpecificValues);
-    }
-
-    public function insert($aValsToAdd = array(), $isIgnore = false)
+    public function insert($aValsToAdd = [], $isIgnore = false)
     {
     	$CNF = $this->_oModule->_oConfig->CNF;
 
-        $aValsToAdd['lr_timestamp'] = time();
-        $aValsToAdd['lr_profile_id'] = (isset($CNF['FIELD_ANONYMOUS']) && isset($this->aInputs[$CNF['FIELD_ANONYMOUS']]) && $this->getCleanValue($CNF['FIELD_ANONYMOUS']) ? -1 : 1) * bx_get_logged_profile_id();
-
-        $iContentId =  parent::insert($aValsToAdd, $isIgnore);
-        if(!empty($iContentId)){
-            $this->processFiles($CNF['FIELD_COVER'], $iContentId, true);
-        }
-        return $iContentId;
+        return parent::insert(array_merge($aValsToAdd, [
+            'lr_timestamp' => time(),
+            'lr_profile_id' => (isset($CNF['FIELD_ANONYMOUS']) && isset($this->aInputs[$CNF['FIELD_ANONYMOUS']]) && $this->getCleanValue($CNF['FIELD_ANONYMOUS']) ? -1 : 1) * bx_get_logged_profile_id()
+        ]), $isIgnore);
     }
 
-    function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
+    public function update ($iContentId, $aValsToAdd = [], &$aTrackTextFieldsChanges = null)
     {
         $CNF = $this->_oModule->_oConfig->CNF;
 
@@ -62,9 +41,7 @@ class BxForumFormEntry extends BxBaseModTextFormEntry
         if (isset($CNF['FIELD_ANONYMOUS']) && isset($this->aInputs[$CNF['FIELD_ANONYMOUS']]) && !$aContentInfo['lr_comment_id'])
             $aValsToAdd['lr_profile_id'] = ($this->getCleanValue($CNF['FIELD_ANONYMOUS']) ? -1 : 1) * abs($aContentInfo['lr_profile_id']);
 
-        $iResult = parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
-        $this->processFiles($CNF['FIELD_COVER'], $iContentId, false);   
-        return $iResult;
+        return parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
     }
     
     public function delete ($iContentId, $aContentInfo = array())
@@ -79,34 +56,6 @@ class BxForumFormEntry extends BxBaseModTextFormEntry
 
         return $mixedResult;
     }
-
-    protected function _getCoverGhostTmplVars($aContentInfo = array())
-    {
-    	$CNF = &$this->_oModule->_oConfig->CNF;
-
-    	return array (
-            'name' => $this->aInputs[$CNF['FIELD_COVER']]['name'],
-            'content_id' => $this->aInputs[$CNF['FIELD_COVER']]['content_id'],
-            'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '',
-            'thumb_id' => isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) ? $aContentInfo[$CNF['FIELD_THUMB']] : 0,
-            'name_thumb' => isset($CNF['FIELD_THUMB']) ? $CNF['FIELD_THUMB'] : ''
-        );
-    }
-
-    protected function _getPhotoGhostTmplVars($aContentInfo = array())
-    {
-    	$CNF = &$this->_oModule->_oConfig->CNF;
-
-    	return array (
-            'name' => $this->aInputs[$CNF['FIELD_PHOTO']]['name'],
-            'content_id' => (int)$this->aInputs[$CNF['FIELD_PHOTO']]['content_id'],
-            'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '',
-            'bx_if:set_thumb' => [
-				'condition' => false,
-				'content' => []
-			],
-    	);
-    }
 }
 
 /** @} */

+ 0 - 101
modules/boonex/posts/classes/BxPostsFormEntry.php

@@ -22,107 +22,6 @@ class BxPostsFormEntry extends BxBaseModTextFormEntry
 
         parent::__construct($aInfo, $oTemplate);
     }
-
-    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($this->aParams['display'] == $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'] && isset($CNF['FIELD_PUBLISHED']) && isset($this->aInputs[$CNF['FIELD_PUBLISHED']]))
-            if($bValues && in_array($aValues[$CNF['FIELD_STATUS']], array('active', 'hidden')))
-                unset($this->aInputs[$CNF['FIELD_PUBLISHED']]);
-
-        if (isset($CNF['FIELD_COVER']) && isset($this->aInputs[$CNF['FIELD_COVER']])) {
-            if($bValues)
-                $this->aInputs[$CNF['FIELD_COVER']]['content_id'] = $aValues['id'];
-
-            $this->aInputs[$CNF['FIELD_COVER']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateCover, $this->_getCoverGhostTmplVars($aContentInfo));
-        }
-
-        parent::initChecker ($aValues, $aSpecificValues);
-    }
-
-    public function insert ($aValsToAdd = array(), $isIgnore = false)
-    {
-        $CNF = &$this->_oModule->_oConfig->CNF;
-
-        if(isset($CNF['FIELD_ADDED']) && empty($aValsToAdd[$CNF['FIELD_ADDED']])) {
-            $iAdded = 0;
-            if(isset($this->aInputs[$CNF['FIELD_ADDED']]))
-                $iAdded = $this->getCleanValue($CNF['FIELD_ADDED']);
-
-            if(empty($iAdded))
-                 $iAdded = time();
-
-            $aValsToAdd[$CNF['FIELD_ADDED']] = $iAdded;
-        }
-
-        if(empty($aValsToAdd[$CNF['FIELD_PUBLISHED']])) {
-            $iPublished = 0;
-            if(isset($this->aInputs[$CNF['FIELD_PUBLISHED']]))
-                $iPublished = $this->getCleanValue($CNF['FIELD_PUBLISHED']);
-                
-             if(empty($iPublished))
-                 $iPublished = time();
-
-             $aValsToAdd[$CNF['FIELD_PUBLISHED']] = $iPublished;
-        }
-
-        $aValsToAdd[$CNF['FIELD_STATUS']] = $aValsToAdd[$CNF['FIELD_PUBLISHED']] > $aValsToAdd[$CNF['FIELD_ADDED']] ? 'awaiting' : 'active';
-
-        $iContentId = parent::insert ($aValsToAdd, $isIgnore);
-        if(!empty($iContentId)){
-            $this->processFiles($CNF['FIELD_COVER'], $iContentId, true);
-        }
-        return $iContentId;
-    }
-
-    function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
-    {
-        $CNF = &$this->_oModule->_oConfig->CNF;
-
-        if(empty($aValsToAdd[$CNF['FIELD_PUBLISHED']]) && isset($this->aInputs[$CNF['FIELD_PUBLISHED']])) {
-            $iPublished = $this->getCleanValue($CNF['FIELD_PUBLISHED']);
-            if(empty($iPublished))
-                $iPublished = time();
-
-            $aValsToAdd[$CNF['FIELD_PUBLISHED']] = $iPublished;
-        }
-
-        $iResult = parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
-        $this->processFiles($CNF['FIELD_COVER'], $iContentId, false);   
-        return $iResult;
-    }
-
-    protected function _getCoverGhostTmplVars($aContentInfo = array())
-    {
-    	$CNF = &$this->_oModule->_oConfig->CNF;
-
-    	return array (
-            'name' => $this->aInputs[$CNF['FIELD_COVER']]['name'],
-            'content_id' => $this->aInputs[$CNF['FIELD_COVER']]['content_id'],
-            'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '',
-            'thumb_id' => isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) ? $aContentInfo[$CNF['FIELD_THUMB']] : 0,
-            'name_thumb' => isset($CNF['FIELD_THUMB']) ? $CNF['FIELD_THUMB'] : '',
-        );
-    }
-
-    protected function _getPhotoGhostTmplVars($aContentInfo = array())
-    {
-    	$CNF = &$this->_oModule->_oConfig->CNF;
-
-    	return array (
-            'name' => $this->aInputs[$CNF['FIELD_PHOTO']]['name'],
-            'content_id' => (int)$this->aInputs[$CNF['FIELD_PHOTO']]['content_id'],
-            'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '',
-            'bx_if:set_thumb' => [
-				'condition' => false,
-				'content' => []
-			],
-    	);
-    }
 }
 
 /** @} */

+ 6 - 68
modules/boonex/reviews/classes/BxReviewsFormEntry.php

@@ -31,53 +31,21 @@ class BxReviewsFormEntry extends BxBaseModTextFormEntry
         }
     }
 
-    function initChecker ($aValues = array (), $aSpecificValues = array())
+    public function insert ($aValsToAdd = [], $isIgnore = false)
     {
         $CNF = &$this->_oModule->_oConfig->CNF;
 
-        $bValues = $aValues && !empty($aValues['id']);
-        $aContentInfo = $bValues ? $this->_oModule->_oDb->getContentInfoById($aValues['id']) : false;
-
-        if (isset($CNF['FIELD_COVER']) && isset($this->aInputs[$CNF['FIELD_COVER']])) {
-            if($bValues)
-                $this->aInputs[$CNF['FIELD_COVER']]['content_id'] = $aValues['id'];
-
-            $this->aInputs[$CNF['FIELD_COVER']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateCover, $this->_getCoverGhostTmplVars($aContentInfo));
-        }
-
-        parent::initChecker ($aValues, $aSpecificValues);
-    }
-
-    public function insert ($aValsToAdd = array(), $isIgnore = false)
-    {
-        $CNF = &$this->_oModule->_oConfig->CNF;
-
-        if(isset($CNF['FIELD_ADDED']) && empty($aValsToAdd[$CNF['FIELD_ADDED']])) {
-            $iAdded = 0;
-            if(isset($this->aInputs[$CNF['FIELD_ADDED']]))
-                $iAdded = $this->getCleanValue($CNF['FIELD_ADDED']);
-            
-            if(empty($iAdded))
-                 $iAdded = time();
-
-            $aValsToAdd[$CNF['FIELD_ADDED']] = $iAdded;
-        }
-
         if (($iReviewFor = $this->safeCustomPostToContext()))
             $aValsToAdd[$CNF['FIELD_ALLOW_VIEW_TO']] = $iReviewFor;
 
         $this->calcAvgVoting($aValsToAdd);
 
         $aValsToAdd[$CNF['FIELD_STATUS']] = 'active';
-
-        $iContentId = parent::insert ($aValsToAdd, $isIgnore);
-        if(!empty($iContentId)){
-            $this->processFiles($CNF['FIELD_COVER'], $iContentId, true);
-        }
-        return $iContentId;
+        
+        return parent::insert ($aValsToAdd, $isIgnore);
     }
 
-    function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
+    public function update ($iContentId, $aValsToAdd = [], &$aTrackTextFieldsChanges = null)
     {
         $CNF = &$this->_oModule->_oConfig->CNF;
 
@@ -85,10 +53,8 @@ class BxReviewsFormEntry extends BxBaseModTextFormEntry
             $aValsToAdd[$CNF['FIELD_ALLOW_VIEW_TO']] = $iReviewFor;
 
         $this->calcAvgVoting($aValsToAdd);
-        
-        $iResult = parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
-        $this->processFiles($CNF['FIELD_COVER'], $iContentId, false);   
-        return $iResult;
+
+        return parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
     }
 
     protected function calcAvgVoting(&$aValsToAdd) {
@@ -134,34 +100,6 @@ class BxReviewsFormEntry extends BxBaseModTextFormEntry
         } else return false;
     }
 
-    protected function _getCoverGhostTmplVars($aContentInfo = array())
-    {
-    	$CNF = &$this->_oModule->_oConfig->CNF;
-
-    	return array (
-            'name' => $this->aInputs[$CNF['FIELD_COVER']]['name'],
-            'content_id' => $this->aInputs[$CNF['FIELD_COVER']]['content_id'],
-            'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '',
-            'thumb_id' => isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) ? $aContentInfo[$CNF['FIELD_THUMB']] : 0,
-            'name_thumb' => isset($CNF['FIELD_THUMB']) ? $CNF['FIELD_THUMB'] : ''
-        );
-    }
-
-    protected function _getPhotoGhostTmplVars($aContentInfo = array())
-    {
-    	$CNF = &$this->_oModule->_oConfig->CNF;
-
-    	return array (
-            'name' => $this->aInputs[$CNF['FIELD_PHOTO']]['name'],
-            'content_id' => (int)$this->aInputs[$CNF['FIELD_PHOTO']]['content_id'],
-            'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '',
-            'bx_if:set_thumb' => [
-				'condition' => false,
-				'content' => []
-			],
-    	);
-    }
-
     protected function genCustomInputVotingOptions ($aInput)
     {
         return $this->_oModule->_oTemplate->getMultiVoting(isset($aInput['value']) ? $aInput['value'] : array(), true);

+ 5 - 83
modules/boonex/stream/classes/BxStrmFormEntry.php

@@ -42,92 +42,14 @@ class BxStrmFormEntry extends BxBaseModTextFormEntry
         }
     }
 
-    function initChecker ($aValues = array (), $aSpecificValues = array())
+    public function insert ($aValsToAdd = [], $isIgnore = false)
     {
         $CNF = &$this->_oModule->_oConfig->CNF;
 
-        $bValues = $aValues && !empty($aValues['id']);
-        $aContentInfo = $bValues ? $this->_oModule->_oDb->getContentInfoById($aValues['id']) : false;
-
-        if($this->aParams['display'] == $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'] && isset($CNF['FIELD_PUBLISHED']) && isset($this->aInputs[$CNF['FIELD_PUBLISHED']]))
-            if($bValues && in_array($aValues[$CNF['FIELD_STATUS']], array('active', 'hidden')))
-                unset($this->aInputs[$CNF['FIELD_PUBLISHED']]);
-
-        if (isset($CNF['FIELD_COVER']) && isset($this->aInputs[$CNF['FIELD_COVER']])) {
-            if($bValues)
-                $this->aInputs[$CNF['FIELD_COVER']]['content_id'] = $aValues['id'];
-
-            $this->aInputs[$CNF['FIELD_COVER']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateCover, $this->_getCoverGhostTmplVars($aContentInfo));
-        }
-
-        parent::initChecker ($aValues, $aSpecificValues);
-    }
-
-    public function insert ($aValsToAdd = array(), $isIgnore = false)
-    {
-        $CNF = &$this->_oModule->_oConfig->CNF;
-
-        if(isset($CNF['FIELD_ADDED']) && empty($aValsToAdd[$CNF['FIELD_ADDED']])) {
-            $iAdded = 0;
-            if(isset($this->aInputs[$CNF['FIELD_ADDED']]))
-                $iAdded = $this->getCleanValue($CNF['FIELD_ADDED']);
-
-            if(empty($iAdded))
-                 $iAdded = time();
-
-            $aValsToAdd[$CNF['FIELD_ADDED']] = $iAdded;
-        }
-
-        if(empty($aValsToAdd[$CNF['FIELD_PUBLISHED']])) {
-            $iPublished = 0;
-            if(isset($this->aInputs[$CNF['FIELD_PUBLISHED']]))
-                $iPublished = $this->getCleanValue($CNF['FIELD_PUBLISHED']);
-                
-             if(empty($iPublished))
-                 $iPublished = time();
-
-             $aValsToAdd[$CNF['FIELD_PUBLISHED']] = $iPublished;
-        }
-
-        $aValsToAdd[$CNF['FIELD_STATUS']] = 'awaiting'; // streams are always in 'awaiting' status inless stream is live
-
-        $aValsToAdd[$CNF['FIELD_KEY']] = genRndPwd(12, false);
-
-        $iContentId = parent::insert ($aValsToAdd, $isIgnore);
-        if(!empty($iContentId)){
-            $this->processFiles($CNF['FIELD_COVER'], $iContentId, true);
-        }
-        return $iContentId;
-    }
-
-    function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
-    {
-        $CNF = &$this->_oModule->_oConfig->CNF;
-
-        if(empty($aValsToAdd[$CNF['FIELD_PUBLISHED']]) && isset($this->aInputs[$CNF['FIELD_PUBLISHED']])) {
-            $iPublished = $this->getCleanValue($CNF['FIELD_PUBLISHED']);
-            if(empty($iPublished))
-                $iPublished = time();
-
-            $aValsToAdd[$CNF['FIELD_PUBLISHED']] = $iPublished;
-        }
-
-        $iResult = parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
-        $this->processFiles($CNF['FIELD_COVER'], $iContentId, false);   
-        return $iResult;
-    }
-
-    protected function _getCoverGhostTmplVars($aContentInfo = array())
-    {
-    	$CNF = &$this->_oModule->_oConfig->CNF;
-
-    	return array (
-            'name' => $this->aInputs[$CNF['FIELD_COVER']]['name'],
-            'content_id' => $this->aInputs[$CNF['FIELD_COVER']]['content_id'],
-            'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '',
-            'thumb_id' => isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) ? $aContentInfo[$CNF['FIELD_THUMB']] : 0,
-            'name_thumb' => isset($CNF['FIELD_THUMB']) ? $CNF['FIELD_THUMB'] : ''
-        );
+        return parent::insert(array_merge($aValsToAdd, [
+            $CNF['FIELD_STATUS'] => 'awaiting', // streams are always in 'awaiting' status inless stream is live
+            $CNF['FIELD_KEY'] => genRndPwd(12, false)
+        ]), $isIgnore);
     }
 }
 

+ 0 - 124
template/scripts/BxBaseAuditServices.php

@@ -39,130 +39,6 @@ class BxBaseAuditServices extends BxDol
         unset($aLevels[MEMBERSHIP_ID_NON_MEMBER]);
         return $aLevels;
     }
-    
-    /**
-     * Comment vote for Notifications module
-     */
-    public function serviceGetNotificationsVote($aEvent)
-    {
-        $iCmtIdUnique = (int)$aEvent['object_id'];
-
-        $aCmtInfo = BxDolCmts::getGlobalInfo($iCmtIdUnique);
-        if(empty($aCmtInfo) || !is_array($aCmtInfo))
-            return array();
-
-        $oCmts = BxDolCmts::getObjectInstance($aCmtInfo['system_name'], 0, false);
-        if(!$oCmts || !$oCmts->isEnabled())
-            return array();
-
-        $oVote = $oCmts->getVoteObject($iCmtIdUnique);
-        if(!$oVote)
-            return array();
-
-        $iCmtId = (int)$aCmtInfo['cmt_id'];
-        $sCmtUrl = str_replace(BX_DOL_URL_ROOT, '{bx_url_root}', $oCmts->serviceGetLink($iCmtId));
-        $sCmtCaption = strmaxtextlen($oCmts->serviceGetText($iCmtId), 20, '...');
-
-        return array(
-            'entry_sample' => $oCmts->getLanguageKey('txt_sample_single'),
-            'entry_url' => $sCmtUrl,
-            'entry_caption' => $sCmtCaption,
-            'entry_author' => $aCmtInfo['author_id'],
-            'subentry_sample' => $oCmts->getLanguageKey('txt_sample_vote_single'),
-            'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
-        );
-    }
-
-    /**
-     * Comment reaction for Notifications module
-     */
-    public function serviceGetNotificationsReaction($aEvent)
-    {
-    	$iCmtIdUnique = (int)$aEvent['object_id'];
-
-        $aCmtInfo = BxDolCmts::getGlobalInfo($iCmtIdUnique);
-        if(empty($aCmtInfo) || !is_array($aCmtInfo))
-            return array();
-
-        $oCmts = BxDolCmts::getObjectInstance($aCmtInfo['system_name'], 0, false);
-        if(!$oCmts || !$oCmts->isEnabled())
-            return array();
-
-        $oReaction = $oCmts->getReactionObject($iCmtIdUnique);
-        if(!$oReaction)
-            return array();
-        
-        $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
-        if(empty($aSubentry) || !is_array($aSubentry))
-            return array();
-
-        $aSubentrySampleParams = array();
-        $aReaction = $oReaction->getReaction($aSubentry['reaction']);
-        if(!empty($aReaction['title']))
-            $aSubentrySampleParams[] = $aReaction['title'];
-        else
-            $aSubentrySampleParams[] = '_undefined';
-
-        $iCmtId = (int)$aCmtInfo['cmt_id'];
-        $sCmtUrl = str_replace(BX_DOL_URL_ROOT, '{bx_url_root}', $oCmts->serviceGetLink($iCmtId));
-        $sCmtCaption = strmaxtextlen($oCmts->serviceGetText($iCmtId), 20, '...');
-
-        return array(
-            'entry_sample' => $oCmts->getLanguageKey('txt_sample_single'),
-            'entry_url' => $sCmtUrl,
-            'entry_caption' => $sCmtCaption,
-            'entry_author' => $aCmtInfo['author_id'],
-            'subentry_sample' => $oCmts->getLanguageKey('txt_sample_reaction_single'),
-            'subentry_sample_params' => $aSubentrySampleParams,
-            'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
-        );
-    }
-
-    /**
-     * Comment score -> vote up for Notifications module
-     */
-    public function serviceGetNotificationsScoreUp($aEvent)
-    {
-    	return $this->_serviceGetNotificationsScore('up', $aEvent);
-    }
-
-    /**
-     * Comment score -> vote down for Notifications module
-     */
-    public function serviceGetNotificationsScoreDown($aEvent)
-    {
-    	return $this->_serviceGetNotificationsScore('down', $aEvent);
-    }
-
-    protected function _serviceGetNotificationsScore($sType, $aEvent)
-    {
-        $iCmtIdUnique = (int)$aEvent['object_id'];
-
-        $aCmtInfo = BxDolCmts::getGlobalInfo($iCmtIdUnique);
-        if(empty($aCmtInfo) || !is_array($aCmtInfo))
-            return array();
-
-        $oCmts = BxDolCmts::getObjectInstance($aCmtInfo['system_name'], 0, false);
-        if(!$oCmts || !$oCmts->isEnabled())
-            return array();
-
-        $oScore = $oCmts->getScoreObject($iCmtIdUnique);
-        if(!$oScore)
-            return array();
-
-        $iCmtId = (int)$aCmtInfo['cmt_id'];
-        $sCmtUrl = str_replace(BX_DOL_URL_ROOT, '{bx_url_root}', $oCmts->serviceGetLink($iCmtId));
-        $sCmtCaption = strmaxtextlen($oCmts->serviceGetText($iCmtId), 20, '...');
-
-        return array(
-            'entry_sample' => $oCmts->getLanguageKey('txt_sample_single'),
-            'entry_url' => $sCmtUrl,
-            'entry_caption' => $sCmtCaption,
-            'entry_author' => $aCmtInfo['author_id'],
-            'subentry_sample' => $oCmts->getLanguageKey('txt_sample_score_' . $sType . '_single'),
-            'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
-        );
-    }
 }
 
 /** @} */

+ 12 - 48
template/scripts/BxBaseCmtsServices.php

@@ -465,43 +465,7 @@ class BxBaseCmtsServices extends BxDol
      */
     public function serviceGetNotificationsVote($aEvent)
     {
-        $iCmtIdUnique = (int)$aEvent['object_id'];
-
-        $aCmtInfo = BxDolCmts::getGlobalInfo($iCmtIdUnique);
-        if(empty($aCmtInfo) || !is_array($aCmtInfo))
-            return array();
-
-        $oCmts = BxDolCmts::getObjectInstance($aCmtInfo['system_name'], 0, false);
-        if(!$oCmts || !$oCmts->isEnabled())
-            return array();
-
-        $oVote = $oCmts->getVoteObject($iCmtIdUnique);
-        if(!$oVote)
-            return array();
-
-        $iCmtId = (int)$aCmtInfo['cmt_id'];
-        $sCmtUrl = str_replace(BX_DOL_URL_ROOT, '{bx_url_root}', $oCmts->serviceGetLink($iCmtId));
-        $sCmtCaption = strmaxtextlen($oCmts->serviceGetText($iCmtId), 20, '...');
-
-        $sCmtUrlApi = '';
-        if(bx_is_api() && getParam('sys_api_comment_notif_link_content') == 'on') {
-            $aCmt = $oCmts->getCommentsBy(['type' => 'uniq_id', 'uniq_id' => $iCmtIdUnique]);
-            if(!empty($aCmt) && is_array($aCmt)) {
-                $oCmts->init($aCmt['cmt_object_id']);
-
-                $sCmtUrlApi = $oCmts->getBaseUrl('{bx_url_root}') . '#cid=' . $iCmtId;
-            }
-        }
-
-        return array(
-            'entry_sample' => $oCmts->getLanguageKey('txt_sample_single'),
-            'entry_url' => $sCmtUrl,
-            'entry_url_api' => $sCmtUrlApi,
-            'entry_caption' => $sCmtCaption,
-            'entry_author' => $aCmtInfo['author_id'],
-            'subentry_sample' => $oCmts->getLanguageKey('txt_sample_vote_single'),
-            'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
-        );
+        return $this->_serviceGetNotificationsVote($aEvent, 'vote');
     }
 
     /**
@@ -565,7 +529,7 @@ class BxBaseCmtsServices extends BxDol
      */
     public function serviceGetNotificationsScoreUp($aEvent)
     {
-    	return $this->_serviceGetNotificationsScore('up', $aEvent);
+    	return $this->_serviceGetNotificationsVote($aEvent, 'score', 'up');
     }
 
     /**
@@ -573,24 +537,24 @@ class BxBaseCmtsServices extends BxDol
      */
     public function serviceGetNotificationsScoreDown($aEvent)
     {
-    	return $this->_serviceGetNotificationsScore('down', $aEvent);
+    	return $this->_serviceGetNotificationsVote($aEvent, 'score', 'down');
     }
 
-    protected function _serviceGetNotificationsScore($sType, $aEvent)
+    protected function _serviceGetNotificationsVote($aEvent, $sAction, $sType = '')
     {
         $iCmtIdUnique = (int)$aEvent['object_id'];
 
         $aCmtInfo = BxDolCmts::getGlobalInfo($iCmtIdUnique);
         if(empty($aCmtInfo) || !is_array($aCmtInfo))
-            return array();
+            return [];
 
         $oCmts = BxDolCmts::getObjectInstance($aCmtInfo['system_name'], 0, false);
         if(!$oCmts || !$oCmts->isEnabled())
-            return array();
+            return [];
 
-        $oScore = $oCmts->getScoreObject($iCmtIdUnique);
-        if(!$oScore)
-            return array();
+        $oAction = $oCmts->{'get' . ucfirst($sAction) . 'Object'}($iCmtIdUnique);
+        if(!$oAction)
+            return [];
 
         $iCmtId = (int)$aCmtInfo['cmt_id'];
         $sCmtUrl = str_replace(BX_DOL_URL_ROOT, '{bx_url_root}', $oCmts->serviceGetLink($iCmtId));
@@ -606,15 +570,15 @@ class BxBaseCmtsServices extends BxDol
             }
         }
 
-        return array(
+        return [
             'entry_sample' => $oCmts->getLanguageKey('txt_sample_single'),
             'entry_url' => $sCmtUrl,
             'entry_url_api' => $sCmtUrlApi,
             'entry_caption' => $sCmtCaption,
             'entry_author' => $aCmtInfo['author_id'],
-            'subentry_sample' => $oCmts->getLanguageKey('txt_sample_score_' . $sType . '_single'),
+            'subentry_sample' => $oCmts->getLanguageKey('txt_sample_' . $sAction . ($sType ? '_' . $sType : '') . '_single'),
             'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
-        );
+        ];
     }
     
     /**