Fork me on GitHub

2.0.18.*版本收不到提醒(通知)的原因分析和解决方案

edited 2012年08月22日 经验心得

很多朋友都遇到了这个问题:
http://vanillaforums.cn/discussion/275 官方的2.0.18.4版本为什么没有通知呢?
http://vanillaforums.cn/discussion/137 我的@ 功能,没实现效果!
http://vanillaforums.cn/discussion/126 请教站长一个问题,关于@ 的使用
http://vanillaforums.cn/discussion/78 @ 之后木有提示是什么情况?

今天彻底跟踪分析了一下相关代码,终于发现了问题根源

决定是否提醒的是这几行代码 (applications/dashboard/models/class.activitymodel.php 498-513行)

public static function NotificationPreference($ActivityType, $Preferences, $Type = NULL) {
    //如果$Type为空,则分别检查$Type为'Email'和'Popup'的提醒偏好,只要其中有一个为1,则返回1
    if ($Type === NULL) {
        $Result = self::NotificationPreference($ActivityType, $Preferences, 'Email')
            || self::NotificationPreference($ActivityType, $Preferences, 'Popup');
        return $Result;
    }
    //获取Preferences.Email.*的配置,默认值为0。即使$Type为'Popup'也是!?——bug所在
    $ConfigPreference = C('Preferences.Email.'.$ActivityType, '0');
    if ($ConfigPreference !== FALSE)
        $Preference = ArrayValue($Type.'.'.$ActivityType, $Preferences, $ConfigPreference);
    else
        $Preference = FALSE;
    var_dump(array($ActivityType,$Preference)); 
    return $Preference;
}

逻辑是这样的:
提醒有两种方式,Email和Popup(站内提醒),如果$Type为空,则分别检查$Type为'Email'和'Popup'的提醒偏好,只要其中有一个为1,则返回1。
如果在用户偏好里面设置过,那么就会按照用户偏好里的设置来提醒,可是如果没有设置,初始的用户偏好却是空的,这种情况下,将按照配置来决定是否提醒,$ConfigPreference = C('Preferences.Email.'.$ActivityType, '0'); ——可是这里的代码出现了bug,无论$Type是'Email'还是'Popup',都去获取了Preferences.Email.*的配置,而Preferences.Email.CommentMention的默认配置是0,导致self::NotificationPreference($ActivityType, $Preferences, 'Email') || self::NotificationPreference($ActivityType, $Preferences, 'Popup');的最终结果为0



解决方案:

方案1. 修正代码(推荐):

虽然我一直不推荐修改代码,但这里的确是原程序的bug
把applications/dashboard/models/class.activitymodel.php 506行
$ConfigPreference = C('Preferences.Email.'.$ActivityType, '0');改为
$ConfigPreference = C('Preferences.'.$Type.'.'.$ActivityType, '0');
我已经向官方git提交了pull request,等待他们接受吧

方案2. 修改配置:

‘将错就错’,既然原程序误读了Preferences.Email.,那就改Preferences.Email.的配置呗
在conf/config.php里加上

$Configuration['Preferences']['Email']['DiscussionMention']     = '1';
$Configuration['Preferences']['Email']['CommentMention']        = '1';

副作用:这样的配置将启用Email和Popup(站内提醒)两种提醒方式,如果你只需要站内提醒不需要Email提醒,那这样配置是不行的
此话题使用的标签:

回复

  • @chuck911 感谢,我去测试下

  • edited 2012年08月22日 #2

    不过建议大家慎用@ 方式,我看官方网站都很少用。并且中文名字还会出错,呵呵。慎重啊
    @ 后,一个人的frofile就会出现两种链接,一个带id,一个不带id,不希望这种混乱。

  • @leon 呵呵,其实@ 是新型论坛的特色啊,官网用的也不算少啊

  • @chuck911 看看腾讯的@ 功能呢 http://t.qq.com/colorful-7
    和个人微博地址就是一样的,看来腾讯这方面考虑还是周密些

  • @leon 汗。。你有点seo链接强迫症,可能是国内站长的通病吧

  • @chuck911 哇哈哈,个人感觉哦。呵呵。其实想想也是有道理的,同一篇内容出现两个链接总觉得不大合理哦。

  • @leon 你打开http://vanillaforums.cn/profile/174/leon 这页的源码,第八行
    <link rel="canonical" href="http://vanillaforums.cn/profile/leon" />
    看看rel=canonical 的意义 http://www.google.com/support/webmasters/bin/answer.py?hl=cn&answer=139394

    vanilla在这些方面还是很规范的

  • edited 2012年08月23日 #8

    @chuck911 哇,刚看了,你的站点还是显示rel="canonical" href="/profile/174/leon"
    我又到官方网站看了,他们的是不带id的,原来@ 是真正的profile链接

  • @chuck911 多谢老大指点。我可以放心的使用@ 了,哈哈

  • @chuck911 另外发现个问题,英文名字的profile的rel都是不带数字id的,为什么中文名字的profile的rel却带了个数字id,是不是因为这个原因导致@ 中文名字时候链接打不开呢?
    期待老大去看看

  • @leon 数字id是照顾到性能,因为数字id是主键,查询的时候会快很多

    你把你站点的.htaccess文件发给我看下,我觉得可能是这个出的问题

  • @chuck911 怎么发给你呢,老大?

  • edited 2012年08月23日 #13

    @chuck911 haode

  • ##
    # @package      Joomla
    # @copyright    Copyright (C) 2005 - 2012 Open Source Matters. All rights reserved.
    # @license      GNU General Public License version 2 or later; see LICENSE.txt
    ##
    
    ##
    # READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE!
    #
    # The line just below this section: 'Options +FollowSymLinks' may cause problems
    # with some server configurations.  It is required for use of mod_rewrite, but may already
    # be set by your server administrator in a way that dissallows changing it in
    # your .htaccess file.  If using it causes your server to error out, comment it out (add # to
    # beginning of line), reload your site in your browser and test your sef url's.  If they work,
    # it has been set by your server administrator and you do not need it set here.
    ##
    
    ## Can be commented out if causes errors, see notes above.
    Options +FollowSymLinks
    
    ## Mod_rewrite in use.
    
    RewriteEngine On
    
    ## Begin - Rewrite rules to block out some common exploits.
    # If you experience problems on your site block out the operations listed below
    # This attempts to block the most common type of exploit `attempts` to Joomla!
    #
    # Block out any script trying to base64_encode data within the URL.
    RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
    # Block out any script that includes a <script> tag in URL.
    RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
    # Block out any script trying to set a PHP GLOBALS variable via URL.
    RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
    # Block out any script trying to modify a _REQUEST variable via URL.
    RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
    # Return 403 Forbidden header and show the content of the root homepage
    RewriteRule .* index.php [F]
    #
    ## End - Rewrite rules to block out some common exploits.
    
    ## Begin - Custom redirects
    #
    # If you need to redirect some pages, or set a canonical non-www to
    # www redirect (or vice versa), place that code here. Ensure those
    # redirects use the correct RewriteRule syntax and the [R=301,L] flags.
    RewriteCond %{HTTP_HOST} ^7colorful.net$ [NC]
    RewriteRule ^(.*)$ http://www.7colorful.net/$1 [R=301,L]
    #
    ## End - Custom redirects
    
    ##
    # Uncomment following line if your webserver's URL
    # is not directly related to physical file paths.
    # Update Your Joomla! Directory (just / for root).
    ##
    
    # RewriteBase /
    
    ## Begin - Joomla! core SEF Section.
    #
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    #
    # If the requested path and file is not /index.php and the request
    # has not already been internally rewritten to the index.php script
    RewriteCond %{REQUEST_URI} !^/index\.php
    # and the request is for something within the component folder,
    # or for the site root, or for an extensionless URL, or the
    # requested URL ends with one of the listed extensions
    RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
    # and the requested path and file doesn't directly match a physical file
    RewriteCond %{REQUEST_FILENAME} !-f
    # and the requested path and file doesn't directly match a physical folder
    RewriteCond %{REQUEST_FILENAME} !-d
    # internally rewrite the request to the index.php script
    RewriteRule .* index.php [L]
    #
    ## End - Joomla! core SEF Section.
    
  • @chuck911 我的vanilla在二级目录,晕,这个是一级目录的,看vanilla的提示好像是要修改目录

  • edited 2012年08月23日 #16

    你看看我vanilla的htaccess

  • edited 2012年08月23日 #17
    # Original
    # If you modify this file then change the above line to: # Modified
    <IfModule mod_rewrite.c>
       RewriteEngine On
       # Certain hosts may require the following line.
       # If vanilla is in a subfolder then you need to specify it after the /. 
       # (ex. You put Vanilla in /forum so change the next line to: RewriteBase /forum)
       RewriteBase /bbs
       RewriteCond %{REQUEST_FILENAME} !-d
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteRule ^(.*)$ index.php\?p=$1 [QSA,L]
    </IfModule>
    

    我已经把RewriteBase改成 /bbs了,还是一样

  • @chuck911 老大帮我看看行吗,感激万分,就是@ 中文链接出问题,中文名字点击的话又没有问题,但是我注意到中文名字链接如果带id就显示正常,因为@ 中文名字默认没有带id,所以显示错误

  • edited 2013年03月15日 #20

    本地测试 把EMAIL提醒勾掉就解决了
    不知道默认设置的代码在哪里修改 默认不勾选EMAIL提醒

  • @chuck911 请问 默认设置的代码在哪里修改 默认不勾选EMAIL提醒 注册用户全部默认站内

  • @coco1013
    默认不启用EMAIL提醒:

    在conf/config.php 中设置

    $Configuration['Preferences']['Email']['ConversationMessage'] = '0';
    $Configuration['Preferences']['Email']['BookmarkComment'] = '0';
    $Configuration['Preferences']['Email']['WallComment'] = '0';
    $Configuration['Preferences']['Email']['ActivityComment'] = '0';
    $Configuration['Preferences']['Email']['DiscussionComment'] = '0';
    $Configuration['Preferences']['Email']['Mention'] = '0';
    

    如果你的vanilla版本是2.0 ,那么需要再根据本贴 “解决方案1” 进行源码修改

  • @chuck911 都搞定了 多谢

登录注册 才能回复。