View source
<?php
function site_verify_menu() {
$items['admin/build/site-verify'] = array(
'title' => 'Site verifications',
'description' => 'Add, change or remove verifications for your site.',
'page callback' => 'site_verify_list',
'access arguments' => array(
'administer site configuration',
),
'file' => 'site_verify.admin.inc',
);
$items['admin/build/site-verify/list'] = array(
'title' => 'List',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['admin/build/site-verify/add'] = array(
'title' => 'Add verification',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'site_verify_edit_form',
),
'access arguments' => array(
'administer site configuration',
),
'file' => 'site_verify.admin.inc',
'type' => MENU_LOCAL_TASK,
);
$items['admin/build/site-verify/add/%site_verify_engine'] = array(
'title' => 'Add',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'site_verify_edit_form',
array(),
4,
),
'access arguments' => array(
'administer site configuration',
),
'file' => 'site_verify.admin.inc',
'type' => MENU_CALLBACK,
);
$items['admin/build/site-verify/%site_verify/edit'] = array(
'page callback' => 'drupal_get_form',
'page arguments' => array(
'site_verify_edit_form',
3,
),
'access arguments' => array(
'administer site configuration',
),
'file' => 'site_verify.admin.inc',
'type' => MENU_CALLBACK,
);
$items['admin/build/site-verify/%site_verify/delete'] = array(
'page callback' => 'drupal_get_form',
'page arguments' => array(
'site_verify_delete_form',
3,
),
'access arguments' => array(
'administer site configuration',
),
'file' => 'site_verify.admin.inc',
'type' => MENU_CALLBACK,
);
$query = db_query("SELECT svid, file FROM {site_verify} WHERE file <> ''");
while ($engine = db_fetch_object($query)) {
$items[$engine->file] = array(
'page callback' => 'site_verify_output',
'page arguments' => array(
(string) $engine->svid,
),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
}
return $items;
}
function site_verify_init() {
if (drupal_is_front_page()) {
$query = db_query("SELECT meta FROM {site_verify} WHERE meta <> ''");
while ($meta = db_result($query)) {
drupal_set_html_head($meta);
}
}
}
function site_verify_load($svid) {
$record = db_fetch_array(db_query("SELECT svid, engine, file, file_contents, meta FROM {site_verify} WHERE svid = %d", $svid));
if ($record) {
$record['engine'] = site_verify_engine_load($record['engine']);
}
return $record;
}
function site_verify_engine_load($engine) {
$engines = site_verify_get_engines();
return isset($engines[$engine]) ? $engines[$engine] : FALSE;
}
function site_verify_site_verify_engine_info() {
$engines['google'] = array(
'name' => t('Google'),
'file' => TRUE,
'file_contents' => TRUE,
'file_example' => 'google1234567890abcdef.html',
'meta' => TRUE,
'meta_example' => '<meta name="google-site-verification" content="NbwaW3WIDp_SPsSsfl78Ive7F34-znm9lxLJXjuWNGE" />',
);
$engines['yahoo'] = array(
'name' => t('Yahoo!'),
'file' => TRUE,
'file_contents' => TRUE,
'meta' => TRUE,
);
$engines['bing'] = array(
'name' => t('Bing'),
'file' => TRUE,
'file_contents' => TRUE,
'meta' => TRUE,
);
$engines['yandex'] = array(
'name' => t('Yandex'),
'file' => TRUE,
'file_example' => 'yandex_b5741169901f6c20.txt',
'meta' => TRUE,
'meta_example' => '<meta name="yandex-verification" content="b5741169901f6c20" />',
);
$engines['custom'] = array(
'name' => t('Custom verification'),
'file' => TRUE,
'file_contents' => TRUE,
'meta' => TRUE,
);
return $engines;
}
function site_verify_get_engines() {
static $engines;
if (!isset($engines)) {
$engines = module_invoke_all('site_verify_engine_info');
drupal_alter('site_verify_engine', $engines);
foreach ($engines as $key => $engine) {
$engines[$key] += array(
'key' => $key,
'file' => FALSE,
'file_example' => FALSE,
'file_validate' => array(),
'file_contents' => FALSE,
'file_contents_example' => FALSE,
'file_contents_validate' => array(),
'meta' => FALSE,
'meta_example' => FALSE,
'meta_validate' => array(),
);
}
}
return $engines;
}
function site_verify_output($svid) {
$verification = site_verify_load($svid);
if ($verification['file_contents'] && $verification['engine']['file_contents']) {
echo $verification['file_contents'];
}
else {
drupal_set_title(t('Verification page'));
return t('This is a verification page for the !title search engine.', array(
'!title' => $verification['engine']['name'],
));
}
}