惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Hugging Face - Blog
Hugging Face - Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
人人都是产品经理
人人都是产品经理
Microsoft Azure Blog
Microsoft Azure Blog
Engineering at Meta
Engineering at Meta
B
Blog RSS Feed
大猫的无限游戏
大猫的无限游戏
博客园_首页
雷峰网
雷峰网
V
Visual Studio Blog
爱范儿
爱范儿
A
About on SuperTechFans
量子位
N
Netflix TechBlog - Medium
Microsoft Security Blog
Microsoft Security Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
MongoDB | Blog
MongoDB | Blog
U
Unit 42
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
月光博客
月光博客
S
SegmentFault 最新的问题
J
Java Code Geeks
H
Hackread – Cybersecurity News, Data Breaches, AI and More

博客园 - jerry data

(转)三维管线自动建模工具PipelineCreator 招聘技巧一二 (转) python抓网页中文乱码问题 - jerry data - 博客园 星 ---- 谷村新司 (转载)arcgis flex api 访问 google 地图 arcgis flex api 访问 google 地图 iframe and margin - jerry data Difference method for Parse XML with C# PInvoke .NET ~ C++ how to call the member function?( C++ ) . or -> "con" function usage tip!! 转载 : flex3 中 Legend fontSize不起作用的bug解决 map service query result maxrecordcount arcmap field calculator Michael F. Goodchild Talks about the Role of Volunteered Geographic Information in a Postmodern GIS World create user with custom profile 唐骏十年管理经验谈:管理者要学会让员工感动 mysql - tutorial 1 theme elements in the form - jerry data
Block development
jerry data · 2009-12-22 · via 博客园 - jerry data

控制block的可用与否,可以在管理员登录网站以后,在Blocks管理页面中,点击指定的block,设置哪些权限用户可以使用该block。 一个module可以创建多个block。

hook_block($op = 'list', $delta = 0, $edit = array())

{

if ($op == 'list') { // drupal 框架会首先使用list参数收集整个程序有哪些block。
$blocks[0]['info'] = t('User login');
// Not worth caching.
$blocks[0]['cache'] = BLOCK_NO_CACHE;

$blocks[1]['info'] = t('Navigation');
// Menu blocks can't be cached because each menu item can have
// a custom access callback. menu.inc manages its own caching.
$blocks[1]['cache'] = BLOCK_NO_CACHE;

$blocks[2]['info'] = t('Who\'s new');

return $blocks;
}

else if ($op == 'view') { // 当需要具体生成block内容的时候,框架使用view参数调用该hook。
$block = array();

switch ($delta) { // 当有多个block时,这个参数指定要渲染按个block,对应的是list里面的数组$blocks索引。
case 0:
// For usability's sake, avoid showing two login forms on one page.
if (!$user->uid && !(arg(0) == 'user' && !is_numeric(arg(1)))) {

$block['subject'] = t('User login');
$block['content'] = drupal_get_form('user_login_block');
}
return $block;

case 1:
if ($menu = menu_tree()) {
$block['subject'] = $user->uid ? check_plain($user->name) : t('Navigation');
$block['content'] = $menu;
}
return $block;

case 2:
if (user_access('access content')) {
// Retrieve a list of new users who have subsequently accessed the site successfully.
$result = db_query_range('SELECT uid, name FROM {users} WHERE status != 0 AND access != 0 ORDER BY created DESC', 0, variable_get('user_block_whois_new_count', 5));
while ($account = db_fetch_object($result)) {
$items[] = $account;
}
$output = theme('user_list', $items);

$block['subject'] = t('Who\'s new');
$block['content'] = $output;
}
return $block;
}


要想控制block显示在那个页面路径下可以通过 'pages' => 'node/*',


$blocks[0] = array(
'info' => t('My Profile'),
);
// A block can provide default settings. In this case we'll enable the
// block and make it visible only on the 'node/*' pages.
$blocks[1] = array(
'info' => t('Example: empty block'),
'status' => TRUE,
'weight' => 0,
'visibility' => 1,
'pages' => 'node/*',
);
return $blocks;

block内容通过$block['content']设置,可以直接在代码中写字符串形式的html,也可以调用theme()函数

$block['content'] = '<a>hello ,world </a>';

$block['content'] = theme("item_list",$items);