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

#1470 Anonymous posting: minor refactoring + implementation Discussions module

Alex Trofimov 8 лет назад
Родитель
Сommit
2b311582fc

+ 14 - 0
inc/classes/BxDolProfile.php

@@ -95,6 +95,20 @@ class BxDolProfile extends BxDolFactory implements iBxDolProfile
         return self::getInstance($mixedProfileId);
     }
 
+    /**
+     * Get singleton instance of Profile by profile id, if profile isn't found it returns instance of BxDolProfileAnonymous or BxDolProfileUndefined
+     */
+    public static function getInstanceMagic($mixedProfileId = false, $bClearCache = false)
+    {
+        if ($mixedProfileId < 0)
+            return BxDolProfileAnonymous::getInstance();
+
+        if (0 == $mixedProfileId || !($oProfile = self::getInstance($mixedProfileId, $bClearCache)))
+            return BxDolProfileUndefined::getInstance();
+        
+        return $oProfile;
+    }
+
     /**
      * Get singleton instance of Profile by profile id
      */

+ 1 - 3
modules/base/general/classes/BxBaseModGeneralMenuSnippetMeta.php

@@ -49,9 +49,7 @@ class BxBaseModGeneralMenuSnippetMeta extends BxTemplMenuCustom
     {
         $CNF = &$this->_oModule->_oConfig->CNF;
 
-        $oProfile = $this->_aContentInfo[$CNF['FIELD_AUTHOR']] < 0 ? BxDolProfileAnonymous::getInstance() : BxDolProfile::getInstance($this->_aContentInfo[$CNF['FIELD_AUTHOR']]);
-        if(!$oProfile) 
-            $oProfile = BxDolProfileUndefined::getInstance();
+        $oProfile = BxDolProfile::getInstanceMagic($this->_aContentInfo[$CNF['FIELD_AUTHOR']]);
 
         return $this->_oTemplate->getUnitMetaItemLink($oProfile->getDisplayName(), array(
             'href' => $oProfile->getUrl(),

+ 1 - 3
modules/base/text/classes/BxBaseModTextTemplate.php

@@ -214,9 +214,7 @@ class BxBaseModTextTemplate extends BxBaseModGeneralTemplate
         // get entry url
         $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aData[$CNF['FIELD_ID']]);
 
-        $oProfile = $aData[$CNF['FIELD_AUTHOR']] < 0 ? BxDolProfileAnonymous::getInstance() : BxDolProfile::getInstance($aData[$CNF['FIELD_AUTHOR']]);        
-        if (!$oProfile) 
-            $oProfile = BxDolProfileUndefined::getInstance();
+        $oProfile = BxDolProfile::getInstanceMagic($aData[$CNF['FIELD_AUTHOR']]);
         
         $sTitle = $this->getTitle($aData);
         $sText = $this->getText($aData);

+ 2 - 1
modules/boonex/forum/classes/BxForumConfig.php

@@ -55,7 +55,8 @@ class BxForumConfig extends BxBaseModTextConfig
         	'FIELD_LOCK' => 'lock',
         	'FIELD_STATUS' => 'status',
             'FIELD_STATUS_ADMIN' => 'status_admin',
-            'FIELD_LABELS' => 'labels',            
+            'FIELD_LABELS' => 'labels',
+            'FIELD_ANONYMOUS' => 'anonymous',
 	        'FIELDS_WITH_KEYWORDS' => 'auto', // can be 'auto', array of fields or comma separated string of field names, works only when OBJECT_METATAGS is specified
 
             // page URIs

+ 12 - 1
modules/boonex/forum/classes/BxForumFormEntry.php

@@ -25,10 +25,21 @@ class BxForumFormEntry extends BxBaseModTextFormEntry
     	$CNF = $this->_oModule->_oConfig->CNF;
 
         $aValsToAdd['lr_timestamp'] = time();
-        $aValsToAdd['lr_profile_id'] = bx_get_logged_profile_id();
+        $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();
 
         return parent::insert($aValsToAdd, $isIgnore);
     }
+
+    function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
+    {
+        $CNF = $this->_oModule->_oConfig->CNF;
+
+        $aContentInfo = $this->_oModule->_oDb->getContentInfoById ($iContentId);
+        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']);
+            
+        return parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
+    }
     
     public function delete ($iContentId, $aContentInfo = array())
     {

+ 1 - 1
modules/boonex/forum/classes/BxForumModule.php

@@ -663,7 +663,7 @@ class BxForumModule extends BxBaseModTextModule
 
         // send notification to author
         if($iProfileId != $aContentInfo[$CNF['FIELD_AUTHOR']]) {
-	        $oProfile = BxDolProfile::getInstance($iProfileId);
+	        $oProfile = BxDolProfile::getInstanceMagic($iProfileId);
 	        if($oProfile) 
                 sendMailTemplate('bx_forum_new_reply', 0, $aContentInfo[$CNF['FIELD_AUTHOR']], array(
                     'SenderDisplayName' => $oProfile->getDisplayName(),

+ 4 - 12
modules/boonex/forum/classes/BxForumTemplate.php

@@ -80,9 +80,7 @@ class BxForumTemplate extends BxBaseModTextTemplate
         );
         $i = 0;
         foreach ($aParticipants as $iProfileId => $iComments) {
-            $oProfile = BxDolProfile::getInstance($iProfileId);
-            if (!$oProfile)
-                continue;
+            $oProfile = BxDolProfile::getInstanceMagic($iProfileId);
 
             $sInfo = '';
             if ($iAuthorId == $iProfileId)
@@ -137,9 +135,7 @@ class BxForumTemplate extends BxBaseModTextTemplate
 
 	function getEntryAuthor($aRow)
     {
-    	$oProfileAuthor = BxDolProfile::getInstance($aRow['author']);
-		if(!$oProfileAuthor)
-			$oProfileAuthor = BxDolProfileUndefined::getInstance();
+    	$oProfileAuthor = BxDolProfile::getInstanceMagic($aRow['author']);
 
     	return $this->parseHtmlByName('entry-author.html', array(
 			'unit' => $oProfileAuthor->getUnit(0, array('template' => 'unit_wo_info')),
@@ -150,9 +146,7 @@ class BxForumTemplate extends BxBaseModTextTemplate
     {
     	$bShowCount = isset($aParams['show_count']) ? (int)$aParams['show_count'] == 1 : false;
 
-		$oProfileLast = BxDolProfile::getInstance($aRow['lr_profile_id']);
-		if(!$oProfileLast)
-			$oProfileLast = BxDolProfileUndefined::getInstance();
+        $oProfileLast = BxDolProfile::getInstanceMagic($aRow['lr_profile_id']);
 
         return $this->parseHtmlByName('entry-label.html', array(
         	'bx_if:show_count' => array(
@@ -173,9 +167,7 @@ class BxForumTemplate extends BxBaseModTextTemplate
         $oModule = BxDolModule::getInstance($this->MODULE);
         $CNF = &$oModule->_oConfig->CNF;
 
-        $oProfileLast = BxDolProfile::getInstance($aRow['lr_profile_id']);
-        if(!$oProfileLast)
-            $oProfileLast = BxDolProfileUndefined::getInstance();
+        $oProfileLast = BxDolProfile::getInstanceMagic($aRow['lr_profile_id']);
 
 		$sTitle = strmaxtextlen($aRow['title'], 100);
         $sText = strmaxtextlen(!empty($aRow['cmt_text']) ? $aRow['cmt_text'] : $aRow['text'], 100);

+ 3 - 2
modules/boonex/forum/install/sql/install.sql

@@ -4,7 +4,7 @@ SET @sStorageEngine = (SELECT `value` FROM `sys_options` WHERE `name` = 'sys_sto
 -- TABLE: entries
 CREATE TABLE IF NOT EXISTS `bx_forum_discussions` (
   `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
-  `author` int(10) unsigned NOT NULL,
+  `author` int(11) NOT NULL,
   `added` int(11) NOT NULL,
   `changed` int(11) NOT NULL,
   `thumb` int(11) NOT NULL,
@@ -13,7 +13,7 @@ CREATE TABLE IF NOT EXISTS `bx_forum_discussions` (
   `text` text NOT NULL,
   `text_comments` text NOT NULL,
   `lr_timestamp` int(11) NOT NULL,
-  `lr_profile_id` int(10) unsigned NOT NULL,
+  `lr_profile_id` int(11) NOT NULL,
   `lr_comment_id` int(11) NOT NULL,
   `views` int(11) NOT NULL default '0',
   `rate` float NOT NULL default '0',
@@ -235,6 +235,7 @@ INSERT INTO `sys_form_inputs`(`object`, `module`, `name`, `value`, `values`, `ch
 (@sName, @sName, 'cat', '', '#!bx_forum_cats', 0, 'select', '_bx_forum_form_entry_input_sys_cat', '_bx_forum_form_entry_input_cat', '', 1, 0, 0, '', '', '', 'avail', '', '_bx_forum_form_entry_input_cat_err', 'Xss', '', 1, 0),
 (@sName, @sName, 'attachments', 'a:1:{i:0;s:14:"bx_forum_html5";}', 'a:2:{s:15:"bx_forum_simple";s:26:"_sys_uploader_simple_title";s:14:"bx_forum_html5";s:25:"_sys_uploader_html5_title";}', 0, 'files', '_bx_forum_form_entry_input_sys_attachments', '_bx_forum_form_entry_input_attachments', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
 (@sName, @sName, 'labels', '', '', 0, 'custom', '_sys_form_input_sys_labels', '_sys_form_input_labels', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
+(@sName, @sName, 'anonymous', '', '', 0, 'switcher', '_sys_form_input_sys_anonymous', '_sys_form_input_anonymous', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
 
 ('bx_forum_search', @sName, 'author', '', '', 0, 'custom', '_bx_forum_form_search_input_sys_author', '_bx_forum_form_search_input_author', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
 ('bx_forum_search', @sName, 'category', '', '#!bx_forum_cats', 0, 'select', '_bx_forum_form_search_input_sys_category', '_bx_forum_form_search_input_category', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),