Drupal所能够理解的资源
Drupal能够识别哪些资源类型?
profile,不知道怎么翻译,应该是指安装类型,固定地存放于profiles目录下。
module,模块,可以存在于多个目录下:modules、profiles/{profile}/modules、sites/all/modules、sites/{$site}/modules。
theme,主题,可以存在于多个目录下:themes、profiles/{profile}/themes、sites/all/themes、sites/{$site}/themes。
theme_engine,主题引擎,可以存在于多个目录下:themes/engines、profiles/{profile}/themes/engines、sites/all/themes/engines、sites/{$site}/themes/engines。
Drupal识别的这些资源都可以注册到系统表system里面,用资源主文件作为key,用type字段表示资源类型。
Drupal如何找到指定的资源?
Drupal使用drupal_get_filename()和drupal_system_listing()两个函数配合来寻找指定的资源。
最先进入的是drupal_get_filename()函数,该函数以资源类型和资源名称作为传入参数:
function drupal_get_filename($type, $name, $filename = NULL) { ... ... }
profile资源固定地存放在profiles目录下,这是在代码里面固定写死了的:
if ($type == 'profile') {
$profile_filename = "profiles/$name/$name.profile";
$files[$type][$name] = file_exists($profile_filename) ? $profile_filename : FALSE;
}
然后在系统表system中搜索对应的资源类型和名称是否有存在。若存在,代表该资源已经安装过,直接返回其key就是资源主文件。
if (function_exists('db_query')) {
$file = db_query("SELECT filename FROM {system} WHERE name = :name AND type = :type", array(':name' => $name, ':type' => $type))->fetchField();
if (file_exists(DRUPAL_ROOT . '/' . $file)) {
$files[$type][$name] = $file;
}
}
在system表找不到对应的资源,Drupal就直接去检查对应的目录是否存在。Drupal规定了每种资源的目录和主文件命名规则:
$dir = $type . 's';
if ($type == 'theme_engine') {
$dir = 'themes/engines';
$extension = 'engine';
}
elseif ($type == 'theme') {
$extension = 'info';
}
else {
$extension = $type;
}
资源目录命名规则是以资源类型加上s后缀,theme_engine例外,theme_engine目录是themes/engines。
资源主文件命名规则是资源名称加上资源类型后缀。theme和theme_engine的后缀例外,theme后缀是info,theme_engine后缀是engine。
每种资源都有多个目录可以存放,Drupal使用drupal_system_listing()函数定义其搜索顺序。
function drupal_system_listing($mask, $directory, $key = 'name', $min_depth = 1) {
$config = conf_path();
$searchdir = array($directory);
$files = array();
// The 'profiles' directory contains pristine collections of modules and
// themes as organized by a distribution. It is pristine in the same way
// that /modules is pristine for core; users should avoid changing anything
// there in favor of sites/all or sites/<domain> directories.
$profiles = array();
$profile = drupal_get_profile();
// In case both profile directories contain the same extension, the actual
// profile always has precedence.
$profiles[] = $profile;
foreach ($profiles as $profile) {
if (file_exists("profiles/$profile/$directory")) {
$searchdir[] = "profiles/$profile/$directory";
}
}
// Always search sites/all/* as well as the global directories.
$searchdir[] = 'sites/all/' . $directory;
if (file_exists("$config/$directory")) {
$searchdir[] = "$config/$directory";
}
// Get current list of items.
if (!function_exists('file_scan_directory')) {
require_once DRUPAL_ROOT . '/includes/file.inc';
}
foreach ($searchdir as $dir) {
$files_to_add = file_scan_directory($dir, $mask, array('key' => $key, 'min_depth' => $min_depth));
// Duplicate files found in later search directories take precedence over
// earlier ones, so we want them to overwrite keys in our resulting
// $files array.
// The exception to this is if the later file is from a module or theme not
// compatible with Drupal core. This may occur during upgrades of Drupal
// core when new modules exist in core while older contrib modules with the
// same name exist in a directory such as sites/all/modules/.
foreach (array_intersect_key($files_to_add, $files) as $file_key => $file) {
// If it has no info file, then we just behave liberally and accept the
// new resource on the list for merging.
if (file_exists($info_file = dirname($file->uri) . '/' . $file->name . '.info')) {
// Get the .info file for the module or theme this file belongs to.
$info = drupal_parse_info_file($info_file);
// If the module or theme is incompatible with Drupal core, remove it
// from the array for the current search directory, so it is not
// overwritten when merged with the $files array.
if (isset($info['core']) && $info['core'] != DRUPAL_CORE_COMPATIBILITY) {
unset($files_to_add[$file_key]);
}
}
}
$files = array_merge($files, $files_to_add);
}
return $files;
}
这里举一个搜索hello模块的例子来说明搜索的过程。根据上面的资源命名规则可以知道,模块目录的命名规则是资源类型加s后缀,也就是modules。然后模块主文件的命名规则是资源名称加上资源类型后缀,也就是hello.module。好了,现在我们要找的就是modules/hello/hello.module文件。那到哪里去找这个文件呢?drupal_system_listing()会依次搜索以下四个位置:
- modules/hello/hello.module
- profiles/drupal_get_profile()/modules/hello/hello.module
- sites/all/modules/hello/hello.module
- sites/conf_path()/modules/hello/hello.module
找到了就OK,找不到就说明hello模块不存在。
Drupal如何载入指定资源?
Drupal用drupal_load()函数载入资源。首先用drupal_get_filename()得到资源主文件,然后简单的include_once就完了。
function drupal_load($type, $name) {
static $files = array();
if (isset($files[$type][$name])) {
return TRUE;
}
$filename = drupal_get_filename($type, $name);
if ($filename) {
include_once DRUPAL_ROOT . '/' . $filename;
$files[$type][$name] = TRUE;
return TRUE;
}
return FALSE;
}
Drupal所能够理解的资源的更多相关文章
- drupal node机制理解
[1]根据结构的功能结构的不同,drupal划分为,node,user,comment等不同的结构,他们的结构是不同的.他们可以作为四个不同的抽象类,根据这个抽象类,分别有一套hook函数去控制实现的 ...
- 深入理解 Kubernetes 资源限制:CPU
原文地址:https://www.yangcs.net/posts/understanding-resource-limits-in-kubernetes-cpu-time/ 在关于 Kubernet ...
- 深入理解Kubernetes资源限制:内存
写在前面 当我开始大范围使用Kubernetes的时候,我开始考虑一个我做实验时没有遇到的问题:当集群里的节点没有足够资源的时候,Pod会卡在Pending状态.你是没有办法给节点增加CPU或者内存的 ...
- 深入理解Kubernetes资源限制:CPU
写在前面 在上一篇关于Kubernetes资源限制的文章我们讨论了如何通过ResourceRequirements设置Pod中容器内存限制,以及容器运行时是如何利用Linux Cgroups实现这些限 ...
- 理解k8s资源限制系列(二):cpu time
本文介绍几种在K8S中限制资源使用的几种方法. 资源类型 在K8S中可以对两类资源进行限制:cpu和内存. CPU的单位有: 正实数,代表分配几颗CPU,可以是小数点,比如0.5代表0.5颗CPU,意 ...
- Drupal中的模块载入
什么是模块载入?首先说载入,这里的载入是指require_once.模块载入就是指require_once模块目录中的某个PHP文件. 每个Drupal模块都应该有自己的主文件.模块主文件以模块名开始 ...
- 对drupal的理解【转】
写本文是想跟刚用drupal的朋友,分享一下心得,国内用drupal的太少了,希望大家能好好交流. 希望几分钟看完后你能马上上手drupal,至少能理解hook,api,theme,module,cc ...
- 服务器资源监控插件(jmeter)
零.引言 我们对被测应用进行性能测试时,除了关注吞吐量.响应时间等应用自身的表现外,对应用运行所涉及的服务器资源的使用情况,也是非常重要的方面,通过 实时监控,可以准确的把握不同测试场景下服务器资源消 ...
- Spring Security之动态配置资源权限
在Spring Security中实现通过数据库动态配置url资源权限,需要通过配置验证过滤器来实现资源权限的加载.验证.系统启动时,到数据库加载系统资源权限列表,当有请求访问时,通过对比系统资源权限 ...
随机推荐
- JZYZOJ1544 [haoi2016T2]放棋子 错排公式 组合数学 高精度
http://172.20.6.3/Problem_Show.asp?ID=1544&a=ProbNF 看了题解才意识到原题有错排的性质(开始根本不知道错排是什么). 十本不同的书放在书架上. ...
- 【DFS】【枚举】Gym - 101246G - Revolutionary Roads
给你一张有向图,问你将任意一条边变成双向后,所能得到的最大强连通分量的大小. 缩点之后,预处理can(i,j)表示i能到j. 之后枚举每一条边(u,v),再枚举其他所有点t,如果can(u,t) &a ...
- datatable无法设置横向滚动条(设置无效)
datatable设置横向滚动条无效 js如下: 页面如下: 设置 scrollx 属性为true时,还需在 table 添加 style="white-space: nowrap; &qu ...
- 操作系统--IO系统任务简述
内核IO---操作系统对于IO的职责 1.对文件和设备命名空间的管理 2.文件和设备访问的控制 3.IO操作控制 4.文件系统的空间分配 5.设备分配 6.IO缓冲管理 7.IO调度方式 8.设备状态 ...
- windows和linux下杀死Tomcat进程,解决端口占用
windows和linux下解决Tomcat进程 windows下启动Tomcat报错,8080端口号被占用,报错信息如下 两种解决方法,一种是关闭了这个端口号,另外一种是修改Tomcat下的serv ...
- OPENCV下SIFT算法使用方法笔记
这几天继续在看Lowe大神的SIFT神作,看的眼花手脚抽筋.也是醉了!!!!实在看不下去,来点干货.我们知道opencv下自带SIFT特征检测以及MATCH匹配的库,这些库完全可以让我们进行傻瓜似的操 ...
- [典型漏洞分享]上传导致的应用层DOS攻击
YS 视频封面设置功能可上传大量图片,可进行资源消耗型DOS攻击[中] 问题描述: YS允许用户为设备设置封面,后台在处理时允许用户间接可控上传图片的二级路径以及直接可控保存图片的文 ...
- 在WPF中使用FontAwesome之类的字体图标
我之前在博客中介绍过几个矢量图库网站,在WPF程序中,一般接触到的矢量图标资源有XAML.SVG.字体这三种格式.XAML是标准格式就不说了,SVG并不是直接支持的,不过微软提供了Expression ...
- String.format("%0"+length+"d", arr)中的%0和"d"分别代表什么
public static void main(String[] args) { int a = 8; String s = String.format("%04d", a); S ...
- android基础知识复习——RelativeLayout布局属性、背景、半透明设置(XML设置)
转自:http://blog.csdn.net/fansongy/article/details/6817968 复习布局与XML,写了一个空的登录界面.XML的注释我写在当行的后面了.程序运行图: ...