| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
|
| 5 |
require_once("default_settings.inc");
|
| 6 |
require_once("googleajaxsearch.inc");
|
| 7 |
|
| 8 |
/**
|
| 9 |
* Implementation of hook_perm
|
| 10 |
*/
|
| 11 |
function googleajaxsearch_perm() {
|
| 12 |
//Access to search blocks could be defined in block settings, so we don't have to add permissions like: 'view google ajax search'.
|
| 13 |
return array('administer google ajax search');
|
| 14 |
}
|
| 15 |
|
| 16 |
/**
|
| 17 |
* Implementation of hook_menu
|
| 18 |
*/
|
| 19 |
function googleajaxsearch_menu() {
|
| 20 |
$items = array();
|
| 21 |
|
| 22 |
// Settings page
|
| 23 |
$items['admin/settings/googleajaxsearch'] = array(
|
| 24 |
'title' => 'Google Ajax Search',
|
| 25 |
'description' => 'Google Ajax Search settings.',
|
| 26 |
'page callback' => 'googleajaxsearch_settings_page',
|
| 27 |
'access arguments' => array('administer google ajax search'),
|
| 28 |
'type' => MENU_NORMAL_ITEM,
|
| 29 |
// 'file' => 'googleajaxsearch.inc',
|
| 30 |
);
|
| 31 |
return $items;
|
| 32 |
}
|
| 33 |
|
| 34 |
/**
|
| 35 |
* Implementation of hook_validate
|
| 36 |
*/
|
| 37 |
function googleajaxsearch_settings_validate($form, &$form_state) {
|
| 38 |
if (!is_numeric($form_state['values']['block_count'])) {
|
| 39 |
form_set_error('block_count', t('You must enter numeric value for this setting.'));
|
| 40 |
}
|
| 41 |
}
|
| 42 |
|
| 43 |
/**
|
| 44 |
* Implementation of hook_block
|
| 45 |
*/
|
| 46 |
function googleajaxsearch_block($op = 'list', $delta = 0, $edit = array()) {
|
| 47 |
switch ($op) {
|
| 48 |
case 'list':
|
| 49 |
$blocks = array();
|
| 50 |
$number_of_blocks = variable_get('block_count', GAS_BLOCKS_NUMBER_DEFAULT);
|
| 51 |
|
| 52 |
for ($i = 0; $i < $number_of_blocks; $i++) {
|
| 53 |
$blocks[$i] = array(
|
| 54 |
'info' => t('Search block @i', array('@i' => $i)),
|
| 55 |
'weight' => GAS_BLOCK_WEIGHT_DEFAULT,
|
| 56 |
'status' => GAS_BLOCK_STATUS_DEFAULT,
|
| 57 |
'region' => GAS_BLOCK_REGION_DEFAULT,
|
| 58 |
'cache' => GAS_BLOCK_CACHE_DEFAULT,
|
| 59 |
);
|
| 60 |
}
|
| 61 |
return $blocks;
|
| 62 |
|
| 63 |
case 'view':
|
| 64 |
return googleajaxsearch_display_block($delta);
|
| 65 |
|
| 66 |
case 'save':
|
| 67 |
gas_set_settings($delta, $edit);
|
| 68 |
break;
|
| 69 |
|
| 70 |
case 'configure':
|
| 71 |
return gas_block_form($delta);
|
| 72 |
}
|
| 73 |
}
|