| 1 |
<?php |
<?php |
| 2 |
// $Id: coder_review_7x.inc,v 1.41 2009/10/18 12:45:36 snpower Exp $ |
// $Id: coder_review_7x.inc,v 1.42 2009/10/18 13:35:57 snpower Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 252 |
|
|
| 253 |
// Block |
// Block |
| 254 |
// http://drupal.org/node/224333#block_optional --- Block module now optional |
// http://drupal.org/node/224333#block_optional --- Block module now optional |
| 255 |
|
array( |
| 256 |
|
'#type' => 'callback', |
| 257 |
|
'#source' => 'allphp', |
| 258 |
|
'#value' => '_coder_review_7x_optional_block_review_callback', |
| 259 |
|
'#warning_callback' => '_coder_review_7x_optional_block_warning', |
| 260 |
|
), |
| 261 |
|
|
| 262 |
// http://drupal.org/node/224333#remove_op |
// http://drupal.org/node/224333#remove_op |
| 263 |
array( |
array( |
| 949 |
} |
} |
| 950 |
|
|
| 951 |
/** |
/** |
| 952 |
|
* Make sure user defined block module as a dependency if using block functions. |
| 953 |
|
* |
| 954 |
|
* @see http://drupal.org/node/224333#block_optional |
| 955 |
|
*/ |
| 956 |
|
function _coder_review_7x_optional_block_review_callback(&$coder_args, $review, $rule, $lines, &$results) { |
| 957 |
|
$functions_to_check = array('block_list', 'block_custom_block_get', 'block_page_build'); |
| 958 |
|
$filename = $coder_args['#filename']; |
| 959 |
|
|
| 960 |
|
// Skip for unit tests as there is no physical file. |
| 961 |
|
if ($filename == 'snippet.php') { |
| 962 |
|
return; |
| 963 |
|
} |
| 964 |
|
|
| 965 |
|
// Find out the info filename and load it. |
| 966 |
|
$pos = strpos($filename, '.'); |
| 967 |
|
$modulename = substr($filename, 0, $pos); |
| 968 |
|
$ini = parse_ini_file($modulename .'.info'); |
| 969 |
|
|
| 970 |
|
// Check if the dependency has been declared. |
| 971 |
|
$dependency_declared = is_array($ini['dependencies']) ? in_array('block', $ini['dependencies']) : FALSE; |
| 972 |
|
|
| 973 |
|
if (file_exists($filename) && $modulename != 'block' && !$dependency_declared) { |
| 974 |
|
if ($lines = file($filename)) { |
| 975 |
|
foreach ($lines as $lineno => $line) { |
| 976 |
|
foreach ($functions_to_check as $function) { |
| 977 |
|
if (preg_match("/[\s\(]$function\(/", $line)) { |
| 978 |
|
$severity_name = _coder_review_severity_name($coder_args, $review, $rule); |
| 979 |
|
$tmprule = $rule; |
| 980 |
|
$tmprule['#warning_callback'] = '_coder_review_7x_optional_block_warning'; |
| 981 |
|
_coder_review_error($results, $tmprule, $severity_name, $lineno, $line); |
| 982 |
|
} |
| 983 |
|
} |
| 984 |
|
} |
| 985 |
|
} |
| 986 |
|
} |
| 987 |
|
} |
| 988 |
|
|
| 989 |
|
/** |
| 990 |
* Define the warning callbacks. |
* Define the warning callbacks. |
| 991 |
*/ |
*/ |
| 992 |
function _coder_review_7x_referer_uri_warning() { |
function _coder_review_7x_referer_uri_warning() { |
| 1927 |
); |
); |
| 1928 |
} |
} |
| 1929 |
|
|
| 1930 |
|
function _coder_review_7x_optional_block_warning() { |
| 1931 |
|
return array( |
| 1932 |
|
'#warning' => t("Block module is now optional, make sure you declare it as a dependency in your module's .info file."), |
| 1933 |
|
'#link' => 'http://drupal.org/node/224333#block_optional', |
| 1934 |
|
); |
| 1935 |
|
} |
| 1936 |
|
|
| 1937 |
function _coder_review_7x_module_implements_warning() { |
function _coder_review_7x_module_implements_warning() { |
| 1938 |
return array( |
return array( |
| 1939 |
'#warning' => t('Use module_implements not module_list when calling hook implementations.'), |
'#warning' => t('Use module_implements not module_list when calling hook implementations.'), |