| 1 |
<?php
|
| 2 |
|
| 3 |
function bpv_form_alter($form_id, &$form) {
|
| 4 |
if ($form_id == 'block_admin_display') {
|
| 5 |
$form['#submit']['bpv_block_admin_submit'] = array();
|
| 6 |
}
|
| 7 |
elseif($form_id == 'block_admin_configure') {
|
| 8 |
$form['page_vis_settings']['visibility']['#disabled'] = TRUE;
|
| 9 |
$form['page_vis_settings']['pages']['#disabled'] = TRUE;
|
| 10 |
$form['page_vis_settings']['#description'] = t('Page specific visibility is being handled by your <strong>bpv_config()</strong> function.');
|
| 11 |
}
|
| 12 |
}
|
| 13 |
|
| 14 |
function bpv_block_admin_submit($form_id, $form_values) {
|
| 15 |
$sql = 'UPDATE blocks SET visibility = 2, pages = CONCAT("<", "?", "php ", "return bpv_is_visible(\'", module, "-", delta, "\'); ", "?", ">") WHERE status=1 AND theme=\'%s\'';
|
| 16 |
db_query($sql, variable_get('theme_default', 'garland'));
|
| 17 |
}
|
| 18 |
|
| 19 |
function bpv_requirements($phase) {
|
| 20 |
if ($phase == 'install') {
|
| 21 |
if (!function_exists('bpv_configuration')) {
|
| 22 |
$t = get_t();
|
| 23 |
return array(
|
| 24 |
array(
|
| 25 |
'title' => $t('Missing the required block control function'),
|
| 26 |
'value' => $t('You must define the function bpv_block_control in your settings.php or in module code before you can install this module. See the README for details.'),
|
| 27 |
'severity' => REQUIREMENT_ERROR)
|
| 28 |
);
|
| 29 |
}
|
| 30 |
}
|
| 31 |
}
|
| 32 |
|
| 33 |
function bpv_is_visible($name) {
|
| 34 |
static $warned = FALSE;
|
| 35 |
|
| 36 |
if (function_exists('bpv_config')) {
|
| 37 |
if (!$block = bpv_config($name)) {
|
| 38 |
$block = array(1, '', '', '');
|
| 39 |
};
|
| 40 |
$match = false;
|
| 41 |
|
| 42 |
if (!$match && isset($block[3])) {
|
| 43 |
$match = $block[3];
|
| 44 |
}
|
| 45 |
if (!$match && isset($block[1]) && $block[1]) {
|
| 46 |
$path = drupal_get_path_alias($_GET['q']);
|
| 47 |
$regexp = '/^('. preg_replace(array('/(\r\n?|\n|\s+)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($block[1], '/')) .')$/';
|
| 48 |
|
| 49 |
// Compare with the internal and path alias (if any).
|
| 50 |
$match = preg_match($regexp, $path);
|
| 51 |
if (!$match && $path != $_GET['q']) {
|
| 52 |
$match = preg_match($regexp, $_GET['q']);
|
| 53 |
}
|
| 54 |
}
|
| 55 |
if (!$match && isset($block[2]) && arg(0) == 'node' && is_numeric(arg(1))) {
|
| 56 |
$node = node_load(arg(1));
|
| 57 |
$match = (array_search($node->type, explode(' ', $block[2])) !== FALSE);
|
| 58 |
}
|
| 59 |
|
| 60 |
$show = ($block[0] xor $match);
|
| 61 |
return $show;
|
| 62 |
}
|
| 63 |
else {
|
| 64 |
if (!$warned) {
|
| 65 |
drupal_set_message(t('An administrator has not defined the function bpv_config(). See bottom of the bpv.module file'), 'error');
|
| 66 |
$warned = TRUE;
|
| 67 |
}
|
| 68 |
return TRUE;
|
| 69 |
}
|
| 70 |
}
|
| 71 |
|
| 72 |
// You may uncomment and edit this function as desired. Or copy/paste to own module.
|
| 73 |
//
|
| 74 |
// Each block entry contains:
|
| 75 |
//
|
| 76 |
// - exclude: whether this is an include or exclude list
|
| 77 |
// - pages: space-separated list of Drupal path globs
|
| 78 |
// - types: space-separated list of node types
|
| 79 |
// - bool: general-purpose boolean
|
| 80 |
//
|
| 81 |
// A block matches if pages or types matches or the boolean is
|
| 82 |
// true. A block is shown if (exclude XOR match).
|
| 83 |
// function bpv_config($name) {
|
| 84 |
// $blocks = array(
|
| 85 |
// 'user-0' => array(0, 'user* node*', '', ''),
|
| 86 |
// 'comment-0' => array(1, '<front>', 'story page', ''),
|
| 87 |
// );
|
| 88 |
// return $blocks[$name];
|
| 89 |
// }
|
| 90 |
|