我正在使用飞溅模块,但我没有得到我想要的结果。我将在用户首次登录时显示一个灯箱表示。我可能会写一个自定义模板,打印到一个块,然后根据一定的条件动态显示块。
我正在处理cookie,下面是我正在处理的一些呼叫:
if (!$cookie_data['time']) {
print $block;
} else { }
非常基本,但我只是想写一个条件来检查它是否是用户的第一次访问
*更新:好的。这是我的错误,我需要它能够做到这一点,只有匿名用户。我的坏。这是我正在使用的代码,但它不能充分工作…
function custommodule_init() {
setcookie('splash_status',$splash_status,time()+3600*24*365);
if (!isset($_COOKIE['splash_status'])) $_COOKIE['splash_status'] = 0;
$splash_status = $_COOKIE['splash_status'] + 1;
if ($splash_status > 1) {
drupal_add_js(drupal_get_path('module', 'sbasplash') . '/sbasplash.js');
drupal_add_css(drupal_get_path('module', 'sbasplash') . '/sbasplash.css');
// Action to enable block
} else {
// Action to disable block
}
}
创建一个自定义模块,实现"hook_user"并在"insert"操作中插入你的代码。当用户第一次插入数据库时,将执行您的代码。您可以使用它来添加您的块或设置会话变量,并根据其值显示您的块。
yourcustommodule_user($op, &$edit, &$account, $category = NULL) {
switch($op){
case 'insert':
//your code here
//example: $_SESSION['show_block'] = 1; and then unset after block is shown
break;
}
}
默认情况下,我认为没有drupal api来检测第一次登录,我们需要一个自定义代码,也许一个新的列属性设置为status = 1,在hook_user为登录检查状态= 1,如果状态为1,然后显示弹出页面,使状态为0,以便下次没有弹出页面
另外,确保您的自定义模块设置为在splash模块之后运行。您可以将模块的system
表中的weight
值设置为高于splash的值,确保在代码检查之前始终设置cookie。