function _ad_check_install in Advertisement 5
Same name and namespace in other branches
- 5.2 ad.module \_ad_check_install()
4 calls to _ad_check_install()
- ad in ./ad.module
- Use this function to display ads from a specified group.
- ad_admin_configure_settings in ./ad.module
- Display a form for the ad module settings.
- ad_admin_groups_list in ./ad.module
- ad_admin_list in ./ad.module
- Build default ad administration page.
File
- ./ad.module, line 2607
- An advertising system for Drupal powered websites.
Code
function _ad_check_install() {
$adserve = variable_get('adserve', '');
$adserveinc = variable_get('adserveinc', '');
if (!file_exists($adserve)) {
$adserve = drupal_get_path('module', 'ad') . '/serve.php';
variable_set('adserve', $adserve);
}
if (!is_readable($adserve)) {
variable_set('adserve', '');
drupal_set_message(t('Failed to read the required file %filename. Please make the file readable by the webserver process. No ads can be displayed until this problem is resolved.', array(
'%filename' => $adserve,
)), 'error');
}
if (!file_exists($adserveinc)) {
$adserveinc = drupal_get_path('module', 'ad') . '/adserve.inc';
variable_set('adserveinc', $adserveinc);
}
if (!is_readable($adserveinc)) {
variable_set('adserveinc', '');
drupal_set_message(t('Failed to read the required file %filename. Please make the file readable by the webserver process. No ads can be displayed until this problem is resolved.', array(
'%filename' => $adserveinc,
)), 'error');
}
$vid = db_result(db_query("SELECT vid FROM {vocabulary} WHERE module = 'ad'"));
if ($vid != variable_get('ad_group_vid', '')) {
drupal_set_message(t('Invalid vocabulary defined for advertisements, attempting to auto-fix.'), 'error');
if ($vid) {
db_query("DELETE FROM {vocabulary_node_types} WHERE vid = %d OR type = 'ad'", variable_get('ad_group_vid', ''));
variable_set('ad_group_vid_restore', variable_get('ad_group_vid', ''));
}
variable_del('ad_group_vid');
}
else {
$result = db_query("SELECT vid FROM {vocabulary_node_types} WHERE type = 'ad'");
$found = FALSE;
while ($vocab = db_fetch_object($result)) {
if ($vocab->vid == variable_get('ad_group_vid', '')) {
$found = TRUE;
}
}
if (!$found) {
drupal_set_message(t('Missing vocabulary node type for advertisements, attempting to auto-fix.'), 'error');
db_query("DELETE FROM {vocabulary_node_types} WHERE vid = %d OR type = 'ad'", variable_get('ad_group_vid', ''));
db_query("DELETE FROM {vocabulary} WHERE vid = %d", variable_get('ad_group_vid', ''));
variable_set('ad_group_vid_restore', variable_get('ad_group_vid', ''));
variable_del('ad_group_vid');
}
}
_ad_get_vid();
if (($old = variable_get('ad_group_vid_restore', '')) && ($vid = variable_get('ad_group_vid', ''))) {
drupal_set_message(t('Restoring orphaned ad group configuration.'));
db_query('UPDATE {term_data} SET vid = %d WHERE vid = %d', $vid, $old);
variable_set('ad_group_vid_restore', '');
}
$result = db_query("SELECT rid FROM {permission} WHERE perm LIKE '%%show advertisements%%'");
if (!db_num_rows($result)) {
drupal_set_message(t('Be sure to enable "!show" permissions for all roles that you wish to see advertisements.', array(
'!show' => l(t('show advertisements'), 'admin/user/access'),
)));
}
$hooks = array(
'init_text',
'select',
'filter',
'exit_text',
);
foreach ($hooks as $hook) {
$adserve_actions = module_invoke_all('adapi', "adserve_{$hook}", array());
$actions = array();
foreach ($adserve_actions as $name => $action) {
if (is_numeric($action['weight'])) {
$weight = $action['weight'];
}
else {
$weight = $action['weight'] = 0;
}
$actions["{$weight}.{$name}"] = $action;
$actions["{$weight}.{$name}"]['name'] = $name;
}
ksort($actions);
variable_set("adserve_{$hook}", serialize($actions));
}
module_invoke_all('adapi', 'check_install', array());
}