Bladeren bron

Ticket #5164 - Notifications: Improve layout and content for different use cases. Point 3.

AntonLV 1 jaar geleden
bovenliggende
commit
c145b2a5f2

+ 26 - 4
inc/classes/BxDolCmts.php

@@ -183,6 +183,7 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
     protected $_sBaseUrl = '';
     protected $_sListAnchor = '';
     protected $_sItemAnchor = '';
+    protected $_sItemAnchorApi = '';
 
     protected $_aSystems = [];
 
@@ -261,6 +262,7 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
 
         $this->_sListAnchor = "cmts-anchor-%s-%d";
         $this->_sItemAnchor = "cmt-anchor-%s-%d-%d";
+        $this->_sItemAnchorApi = "cid=%d";
 
         $this->_oQuery = new BxDolCmtsQuery($this);
 
@@ -539,24 +541,39 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
         return bx_absolute_url($sUrl, $sPrefix);
     }
 
-    public function getListUrl()
+    public function getListUrl($sPrefix = BX_DOL_URL_ROOT)
     {
-        $sBaseUrl = $this->getBaseUrl();
+        $sBaseUrl = $this->getBaseUrl($sPrefix);
         if(empty($sBaseUrl))
             return '';
 
         return $sBaseUrl . $this->getListAnchor(true);
     }
 
-    public function getItemUrl($iItemId)
+    /**
+     * Get URL for view commented content page with anchor to the coment. 
+     * @param integer $iItemId - comment ID.
+     * @param string $sPrefix - URL prefix.
+     * @return string with URL.
+     */
+    public function getItemUrl($iItemId, $sPrefix = BX_DOL_URL_ROOT)
     {
-        $sBaseUrl = $this->getBaseUrl();
+        $sBaseUrl = $this->getBaseUrl($sPrefix);
         if(empty($sBaseUrl))
             return '';
 
         return $sBaseUrl . $this->getItemAnchor($iItemId, true);
     }
 
+    public function getItemUrlApi($iItemId, $sPrefix = BX_DOL_URL_ROOT)
+    {
+        $sBaseUrl = $this->getBaseUrl($sPrefix);
+        if(empty($sBaseUrl))
+            return '';
+
+        return $sBaseUrl . $this->getItemAnchorApi($iItemId, true);
+    }
+
     public function getListAnchor($bWithHash = false)
     {
         return ($bWithHash ? '#' : '') . sprintf($this->_sListAnchor, str_replace('_', '-', $this->getSystemName()), $this->getId());
@@ -567,6 +584,11 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
         return ($bWithHash ? '#' : '') . sprintf($this->_sItemAnchor, str_replace('_', '-', $this->getSystemName()), $this->getId(), $iItemId);
     }
 
+    public function getItemAnchorApi($iItemId, $bWithHash = false)
+    {
+        return ($bWithHash ? '#' : '') . sprintf($this->_sItemAnchorApi, $iItemId);
+    }
+
     public function getAttachments($iCmtId)
     {
         $aResult = array();

+ 0 - 1
install/sql/system.sql

@@ -839,7 +839,6 @@ INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `ex
 (@iCategoryId, 'sys_api_context_switcher', '_adm_stg_cpt_option_sys_api_context_switcher', '', 'select', 'a:3:{s:6:"module";s:6:"system";s:6:"method";s:32:"get_options_api_context_switcher";s:5:"class";s:13:"TemplServices";}', '', '', 2),
 (@iCategoryId, 'sys_api_context_connection', '_adm_stg_cpt_option_sys_api_context_connection', '', 'select', 'a:3:{s:6:"module";s:6:"system";s:6:"method";s:34:"get_options_api_context_connection";s:5:"class";s:13:"TemplServices";}', '', '', 3),
 (@iCategoryId, 'sys_api_comments_flat', '_adm_stg_cpt_option_sys_api_comments_flat', '', 'checkbox', '', '', '', 10),
-(@iCategoryId, 'sys_api_comment_notif_link_content', '_adm_stg_cpt_option_sys_api_comment_notif_link_content', '', 'checkbox', '', '', '', 15),
 (@iCategoryId, 'sys_api_search_sections', '_adm_stg_cpt_option_sys_api_search_sections', 'bx_posts,bx_persons,bx_groups', 'digit', '', '', '', 20),
 (@iCategoryId, 'sys_api_extended_units', '_adm_stg_cpt_option_sys_api_extended_units', '', 'checkbox', '', '', '', 30),
 (@iCategoryId, 'sys_api_conn_in_prof_units', '_adm_stg_cpt_option_sys_api_conn_in_prof_units', '', 'checkbox', '', '', '', 31);

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

@@ -2780,9 +2780,9 @@ class BxBaseModGeneralModule extends BxDolModule
      */
     public function serviceGetNotificationsComment($aEvent)
     {
-    	$CNF = &$this->_oConfig->CNF;
+        $CNF = &$this->_oConfig->CNF;
 
-    	$iContentId = (int)$aEvent['object_id'];
+        $iContentId = (int)$aEvent['object_id'];
         $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
         if(empty($aContentInfo) || !is_array($aContentInfo))
             return [];
@@ -2804,7 +2804,8 @@ class BxBaseModGeneralModule extends BxDolModule
             'entry_summary' => $sEntrySummary,
             'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
             'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
-            'subentry_url' => bx_absolute_url($oComment->getViewUrl($iCommentId, false), '{bx_url_root}'),
+            '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.
         ];
@@ -2815,36 +2816,32 @@ class BxBaseModGeneralModule extends BxDolModule
      */
     public function serviceGetNotificationsReply($aEvent)
     {
-    	$CNF = &$this->_oConfig->CNF;
+        $CNF = &$this->_oConfig->CNF;
 
-    	$oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], 0, false);
+        $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));
+        $iParentId = (int)$aEvent['object_id'];
+        $aParentInfo = $oComment->getQueryObject()->getCommentsBy(['type' => 'id', 'id' => $iParentId]);
         if(empty($aParentInfo) || !is_array($aParentInfo))
             return [];
 
         $iObjectId = (int)$aParentInfo['cmt_object_id'];
         $oComment->init($iObjectId);
-
-        $sParentUrlApi = '';
-        if($this->_bIsApi && getParam('sys_api_comment_notif_link_content') == 'on')
-            $sParentUrlApi = $oComment->getBaseUrl('{bx_url_root}') . '#cid=' . $iParentId;
-
         $iCommentId = (int)$aEvent['subobject_id'];
 
         return [
             'object_id' => $iObjectId,
             'entry_sample' => '_cmt_txt_sample_comment_single',
-            'entry_url' => bx_absolute_url($oComment->getViewUrl($iParentId, false), '{bx_url_root}'),
-            'entry_url_api' => $sParentUrlApi,
+            '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' => bx_absolute_url($oComment->getViewUrl($iCommentId, false), '{bx_url_root}'),
+            '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.
         ];

+ 0 - 1
modules/boonex/english/data/langs/system/en.xml

@@ -1813,7 +1813,6 @@
     <string name="_adm_stg_cpt_option_sys_api_cnt_cnn_fans"><![CDATA[membership]]></string>
     <string name="_adm_stg_cpt_option_sys_api_cnt_cnn_participants"><![CDATA[any participation]]></string>
     <string name="_adm_stg_cpt_option_sys_api_comments_flat"><![CDATA[Flat comments]]></string>
-    <string name="_adm_stg_cpt_option_sys_api_comment_notif_link_content"><![CDATA[Link notifications related to actions with a comment to commented content]]></string>
     <string name="_adm_stg_cpt_option_sys_api_search_sections"><![CDATA[Search sections]]></string>
     <string name="_adm_stg_cpt_option_sys_api_extended_units"><![CDATA[Use extended units]]></string>
     <string name="_adm_stg_cpt_option_sys_api_conn_in_prof_units"><![CDATA[Use connections lists in profiles/groups units]]></string>

+ 0 - 1
modules/boonex/russian/data/langs/system/ru.xml

@@ -1788,7 +1788,6 @@
     <string name="_adm_stg_cpt_option_sys_api_cnt_cnn_fans"><![CDATA[членство]]></string>
     <string name="_adm_stg_cpt_option_sys_api_cnt_cnn_participants"><![CDATA[любое участие]]></string>
     <string name="_adm_stg_cpt_option_sys_api_comments_flat"><![CDATA[Линейные комментарии]]></string>
-    <string name="_adm_stg_cpt_option_sys_api_comment_notif_link_content"><![CDATA[Связывать уведомления, связанные с действиями с комментарием, с комментируемым контентом]]></string>
     <string name="_adm_stg_cpt_option_sys_api_search_sections"><![CDATA[Искать в]]></string>
     <string name="_adm_stg_cpt_option_sys_api_extended_units"><![CDATA[Использовать расширенные юниты]]></string>
     <string name="_adm_stg_cpt_option_sys_api_conn_in_prof_units"><![CDATA[Использовать списки связей в блоках профилей/групп.]]></string>

+ 7 - 5
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -2615,7 +2615,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
      */
     public function serviceGetNotificationsComment($aEvent)
     {
-    	$CNF = &$this->_oConfig->CNF;
+        $CNF = &$this->_oConfig->CNF;
 
         $iContent = (int)$aEvent['object_id'];
         $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
@@ -2638,7 +2638,8 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
             'entry_summary' => $sEntrySummary,
             'entry_author' => $aContent['owner_id'],
             'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
-            'subentry_url' => bx_absolute_url($oComment->getViewUrl($iCommentId, false), '{bx_url_root}'),
+            '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.
         ];
@@ -2677,18 +2678,19 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
 
         $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' => bx_absolute_url($oComment->getViewUrl($iParentId, false), '{bx_url_root}'),
+            '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' => bx_absolute_url($oComment->getViewUrl($iCommentId, false), '{bx_url_root}'),
+            '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.
         ];

+ 10 - 7
template/scripts/BxBaseServiceMetatags.php

@@ -108,21 +108,23 @@ class BxBaseServiceMetatags extends BxDol
      */
     public function serviceGetNotificationsPostMention($aEvent)
     {
-    	$iProfile = (int)$aEvent['object_owner_id'];
-    	$oProfile = BxDolProfile::getInstance($iProfile);
+        $iProfile = (int)$aEvent['object_owner_id'];
+        $oProfile = BxDolProfile::getInstance($iProfile);
         if(!$oProfile)
             return [];
 
-        $sEntryUrl = '';
+        $sEntryUrl = $sEntryUrlApi = '';
         if (isset($aEvent['content']['module']) && isset($aEvent['content']['content_id'])) {
             if ('sys_cmts' == $aEvent['content']['module']) {
                 $oCmts = BxDolCmts::getObjectInstanceByUniqId($aEvent['content']['content_id']);
                 $aCmt = BxDolCmtsQuery::getCommentExtendedByUniqId($aEvent['content']['content_id']);
-                if ($oCmts && $aCmt)
-                    $sEntryUrl = $oCmts->getViewUrl($aCmt['cmt_id']);
-            } elseif (BxDolRequest::serviceExists($aEvent['content']['module'], 'get_link')) {
-                $sEntryUrl = str_replace(BX_DOL_URL_ROOT, '{bx_url_root}', bx_srv($aEvent['content']['module'], 'get_link', [$aEvent['content']['content_id']]));
+                if ($oCmts && $aCmt) {
+                    $sEntryUrl = $oCmts->getItemUrl($aCmt['cmt_id'], '{bx_url_root}');
+                    $sEntryUrlApi = $oCmts->getItemUrlApi($aCmt['cmt_id'], '{bx_url_root}');
+                }
             }
+            elseif (BxDolRequest::serviceExists($aEvent['content']['module'], 'get_link'))
+                $sEntryUrl = str_replace(BX_DOL_URL_ROOT, '{bx_url_root}', bx_srv($aEvent['content']['module'], 'get_link', [$aEvent['content']['content_id']]));
         }
 
         if(!$sEntryUrl)
@@ -131,6 +133,7 @@ class BxBaseServiceMetatags extends BxDol
         return [
             'entry_sample' => '_sys_profile_sample_single',
             'entry_url' => $sEntryUrl,
+            'entry_url_api' => $sEntryUrlApi,
             'entry_caption' => $oProfile->getDisplayName(),
             'entry_author' => $iProfile,
             'lang_key' => '_sys_metatags_mention_added',