You are here

simpleads.install in SimpleAds 7.2

Same filename and directory in other branches
  1. 8 simpleads.install
  2. 7 simpleads.install

SimpleAds module install.

File

simpleads.install
View source
<?php

/**
 * @file
 * SimpleAds module install.
 */

/**
 * Implements hook_install().
 */
function simpleads_install() {
  $t = get_t();
  $vocabulary = (object) array(
    'name' => $t('Simpleads groups'),
    'machine_name' => 'simpleads_groups',
    'help' => '',
  );
  taxonomy_vocabulary_save($vocabulary);
  $groups = array(
    $t('Sidebar Ads'),
    $t('Content Ads'),
  );
  $group_vid = db_select('taxonomy_vocabulary', 'tv')
    ->fields('tv', array(
    'vid',
  ))
    ->condition('machine_name', 'simpleads_groups')
    ->execute()
    ->fetchField();
  foreach ($groups as $name) {
    $term = new stdClass();
    $term->name = $name;
    $term->vid = $group_vid;
    taxonomy_term_save($term);
  }
  $fields = array(
    array(
      'active' => '1',
      'cardinality' => '1',
      'deleted' => '0',
      'entity_types' => array(),
      'field_name' => 'field_ad_type',
      'foreign keys' => array(),
      'indexes' => array(
        'value' => array(
          0 => 'value',
        ),
      ),
      'locked' => '1',
      'module' => 'list',
      'settings' => array(
        'allowed_values' => array(),
        'allowed_values_function' => '_simpleads_ad_types',
      ),
      'translatable' => '1',
      'type' => 'list_text',
    ),
    array(
      'active' => '1',
      'cardinality' => '1',
      'deleted' => '0',
      'entity_types' => array(),
      'field_name' => 'field_ad_image',
      'foreign keys' => array(
        'fid' => array(
          'columns' => array(
            'fid' => 'fid',
          ),
          'table' => 'file_managed',
        ),
      ),
      'indexes' => array(
        'fid' => array(
          0 => 'fid',
        ),
      ),
      'locked' => '1',
      'module' => 'image',
      'settings' => array(
        'default_image' => FALSE,
        'uri_scheme' => 'public',
      ),
      'translatable' => '1',
      'type' => 'image',
    ),
    array(
      'active' => '1',
      'cardinality' => '1',
      'deleted' => '0',
      'entity_types' => array(),
      'field_name' => 'field_ad_flash',
      'foreign keys' => array(
        'fid' => array(
          'columns' => array(
            'fid' => 'fid',
          ),
          'table' => 'file_managed',
        ),
      ),
      'indexes' => array(
        'fid' => array(
          0 => 'fid',
        ),
      ),
      'locked' => '1',
      'module' => 'file',
      'settings' => array(
        'default_image' => FALSE,
        'display_default' => 0,
        'display_field' => 0,
        'uri_scheme' => 'public',
      ),
      'translatable' => '1',
      'type' => 'file',
    ),
    array(
      'active' => '1',
      'cardinality' => '1',
      'deleted' => '0',
      'entity_types' => array(),
      'field_name' => 'field_ad_text',
      'foreign keys' => array(
        'format' => array(
          'columns' => array(
            'format' => 'format',
          ),
          'table' => 'filter_format',
        ),
      ),
      'indexes' => array(
        'format' => array(
          0 => 'format',
        ),
      ),
      'locked' => '1',
      'module' => 'text',
      'settings' => array(),
      'translatable' => '1',
      'type' => 'text_long',
    ),
    array(
      'active' => '1',
      'cardinality' => '1',
      'deleted' => '0',
      'entity_types' => array(),
      'field_name' => 'field_ad_url',
      'foreign keys' => array(),
      'indexes' => array(),
      'locked' => '1',
      'module' => 'link',
      'settings' => array(
        'attributes' => array(
          'class' => '',
          'rel' => '',
          'target' => 'default',
        ),
        'display' => array(
          'url_cutoff' => 80,
        ),
        'enable_tokens' => 1,
        'title' => 'optional',
        'title_maxlength' => 128,
        'title_value' => '',
        'url' => 0,
      ),
      'translatable' => '0',
      'type' => 'link_field',
    ),
    array(
      'active' => 1,
      'cardinality' => -1,
      'deleted' => 0,
      'entity_types' => array(),
      'field_name' => 'field_ad_category',
      'foreign keys' => array(
        'tid' => array(
          'columns' => array(
            'tid' => 'tid',
          ),
          'table' => 'taxonomy_term_data',
        ),
      ),
      'indexes' => array(
        'tid' => array(
          0 => 'tid',
        ),
      ),
      'locked' => '1',
      'module' => 'taxonomy',
      'settings' => array(
        'allowed_values' => array(
          0 => array(
            'vocabulary' => 'simpleads_groups',
            'parent' => 0,
          ),
        ),
      ),
      'translatable' => '0',
      'type' => 'taxonomy_term_reference',
    ),
    array(
      'field_name' => 'field_ad_date',
      'active' => '1',
      'cardinality' => '1',
      'deleted' => '0',
      'entity_types' => array(),
      'foreign keys' => array(),
      'indexes' => array(),
      'locked' => 1,
      'module' => 'date',
      'settings' => array(
        'cache_count' => '4',
        'cache_enabled' => 0,
        'granularity' => array(
          'day' => 'day',
          'hour' => 'hour',
          'minute' => 'minute',
          'month' => 'month',
          'second' => 0,
          'year' => 'year',
        ),
        'timezone_db' => 'UTC',
        'todate' => 'optional',
        'tz_handling' => 'site',
      ),
      'translatable' => '0',
      'type' => 'datetime',
    ),
  );
  foreach ($fields as $field) {
    field_create_field($field);
  }
  $instance = array(
    'bundle' => 'simpleads',
    'default_value' => array(
      0 => array(
        'value' => 'graphic',
      ),
    ),
    'deleted' => '0',
    'description' => 'Please select advertisement type.',
    'display' => array(
      'default' => array(
        'label' => 'hidden',
        'module' => 'list',
        'settings' => array(),
        'type' => 'hidden',
        'weight' => -1,
      ),
      'teaser' => array(
        'label' => 'hidden',
        'module' => 'list',
        'settings' => array(),
        'type' => 'hidden',
        'weight' => -1,
      ),
    ),
    'entity_type' => 'node',
    'field_name' => 'field_ad_type',
    'label' => 'Advertisement type',
    'required' => TRUE,
    'settings' => array(
      'allowed_values_function' => '_simpleads_ad_types',
      'user_register_form' => FALSE,
    ),
    'user_register_form' => FALSE,
    'widget' => array(
      'active' => 1,
      'module' => 'options',
      'settings' => array(),
      'type' => 'options_select',
      'weight' => -4,
    ),
  );
  field_create_instance($instance);
  $instance = array(
    'bundle' => 'simpleads',
    'deleted' => '0',
    'description' => 'Upload an image for this advertisement.',
    'display' => array(
      'default' => array(
        'label' => 'hidden',
        'module' => 'image',
        'settings' => array(
          'image_link' => '',
          'image_style' => 'large',
        ),
        'type' => 'image',
        'weight' => -1,
      ),
      'teaser' => array(
        'label' => 'hidden',
        'module' => 'image',
        'settings' => array(
          'image_link' => 'content',
          'image_style' => 'medium',
        ),
        'type' => 'image',
        'weight' => -1,
      ),
    ),
    'entity_type' => 'node',
    'field_name' => 'field_ad_image',
    'label' => 'Image advertisement',
    'required' => FALSE,
    'settings' => array(
      'alt_field' => TRUE,
      'default_image' => 0,
      'file_directory' => 'field/image',
      'file_extensions' => 'png gif jpg jpeg',
      'max_filesize' => '',
      'max_resolution' => '',
      'min_resolution' => '',
      'title_field' => TRUE,
      'user_register_form' => FALSE,
    ),
    'widget' => array(
      'module' => 'image',
      'settings' => array(
        'preview_image_style' => 'thumbnail',
        'progress_indicator' => 'throbber',
      ),
      'type' => 'image_image',
      'weight' => '2',
    ),
  );
  field_create_instance($instance);
  $instance = array(
    'bundle' => 'simpleads',
    'deleted' => '0',
    'description' => 'Upload Flash file for this advertisement.',
    'display' => array(
      'default' => array(
        'label' => 'hidden',
        'module' => 'file',
        'settings' => array(),
        'type' => 'file_default',
        'weight' => -1,
      ),
      'teaser' => array(
        'label' => 'hidden',
        'module' => 'file',
        'settings' => array(),
        'type' => 'file_default',
        'weight' => -1,
      ),
    ),
    'entity_type' => 'node',
    'field_name' => 'field_ad_flash',
    'label' => 'Flash advertisement',
    'required' => 0,
    'settings' => array(
      'alt_field' => FALSE,
      'description_field' => 0,
      'file_directory' => 'field/flash',
      'file_extensions' => 'swf',
      'max_filesize' => '',
      'max_resolution' => '',
      'min_resolution' => '',
      'title_field' => '',
      'user_register_form' => FALSE,
    ),
    'widget' => array(
      'module' => 'file',
      'settings' => array(
        'progress_indicator' => 'throbber',
      ),
      'type' => 'file_generic',
      'weight' => -1,
    ),
  );
  field_create_instance($instance);
  $instance = array(
    'bundle' => 'simpleads',
    'default_value' => NULL,
    'deleted' => '0',
    'description' => 'Enter your text ad. If you would like to embed media, please configure WYSIWYG editor and input format settings.',
    'display' => array(
      'default' => array(
        'label' => 'hidden',
        'module' => 'text',
        'settings' => array(),
        'type' => 'text_default',
        'weight' => -1,
      ),
      'teaser' => array(
        'label' => 'hidden',
        'module' => 'text',
        'settings' => array(),
        'type' => 'text_default',
        'weight' => -1,
      ),
    ),
    'entity_type' => 'node',
    'field_name' => 'field_ad_text',
    'label' => 'Text advertisement',
    'required' => FALSE,
    'settings' => array(
      'rows' => 5,
      'text_processing' => 1,
      'user_register_form' => FALSE,
    ),
    'widget' => array(
      'module' => 'text',
      'settings' => array(
        'rows' => 5,
      ),
      'type' => 'text_textarea',
      'weight' => 0,
    ),
  );
  field_create_instance($instance);
  $instance = array(
    'bundle' => 'simpleads',
    'default_value' => NULL,
    'deleted' => '0',
    'description' => '',
    'display' => array(
      'default' => array(
        'label' => 'hidden',
        'module' => 'link',
        'settings' => array(),
        'type' => 'hidden',
        'weight' => 13,
      ),
      'teaser' => array(
        'label' => 'hidden',
        'settings' => array(),
        'type' => 'hidden',
        'weight' => 0,
      ),
    ),
    'entity_type' => 'node',
    'field_name' => 'field_ad_url',
    'label' => 'URL Address',
    'required' => TRUE,
    'settings' => array(
      'attributes' => array(
        'class' => '',
        'configurable_title' => 0,
        'rel' => '',
        'target' => 'user',
        'title' => '',
      ),
      'display' => array(
        'url_cutoff' => '80',
      ),
      'enable_tokens' => 1,
      'title' => 'none',
      'title_maxlength' => '128',
      'title_value' => '',
      'url' => 0,
      'user_register_form' => FALSE,
      'validate_url' => 1,
    ),
    'widget' => array(
      'active' => 0,
      'module' => 'link',
      'settings' => array(),
      'type' => 'link_field',
      'weight' => '2',
    ),
  );
  field_create_instance($instance);
  $instance = array(
    'bundle' => 'simpleads',
    'default_value' => NULL,
    'deleted' => '0',
    'description' => '',
    'display' => array(
      'default' => array(
        'label' => 'above',
        'settings' => array(),
        'type' => 'hidden',
        'weight' => 14,
      ),
      'teaser' => array(
        'label' => 'above',
        'settings' => array(),
        'type' => 'hidden',
        'weight' => 1,
      ),
    ),
    'entity_type' => 'node',
    'field_name' => 'field_ad_category',
    'label' => 'Advertisement groups',
    'required' => TRUE,
    'settings' => array(
      'user_register_form' => FALSE,
    ),
    'widget' => array(
      'active' => 1,
      'module' => 'options',
      'settings' => array(),
      'type' => 'options_buttons',
      'weight' => -4,
    ),
  );
  field_create_instance($instance);
  $instance = array(
    'bundle' => 'simpleads',
    'deleted' => '0',
    'description' => '',
    'display' => array(
      'default' => array(
        'label' => 'above',
        'module' => 'date',
        'settings' => array(
          'format_type' => 'long',
          'fromto' => 'both',
          'multiple_from' => '',
          'multiple_number' => '',
          'multiple_to' => '',
        ),
        'type' => 'date_default',
        'weight' => 1,
      ),
      'teaser' => array(
        'label' => 'above',
        'settings' => array(),
        'type' => 'hidden',
        'weight' => 0,
      ),
    ),
    'entity_type' => 'node',
    'field_name' => 'field_ad_date',
    'label' => 'date',
    'required' => 0,
    'settings' => array(
      'default_value' => 'now',
      'default_value2' => '',
      'default_value_code' => '',
      'default_value_code2' => '',
      'user_register_form' => FALSE,
    ),
    'widget' => array(
      'active' => 1,
      'module' => 'date',
      'settings' => array(
        'increment' => '15',
        'input_format' => 'm/d/Y - H:i:s',
        'input_format_custom' => '',
        'label_position' => 'above',
        'text_parts' => array(),
        'year_range' => '-3:+3',
      ),
      'type' => 'date_popup',
      'weight' => '-3',
    ),
  );
  field_create_instance($instance);

  // Translatables
  // Included for use with string extractors like potx.
  $t('Advertisement groups');
  $t('Advertisement type');
  $t('Enter your text ad. If you would like to embed media, please configure WYSIWYG editor and input format settings.');
  $t('Flash advertisement');
  $t('Image advertisement');
  $t('Please select advertisement type.');
  $t('Text advertisement');
  node_types_rebuild();

  // Count clicks and impressions of any anonymous users.
  user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array(
    'count advertisement impressions',
    'count advertisement clicks',
  ));

  // Count clicks and impressions of all authenticated users.
  user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array(
    'count advertisement impressions',
    'count advertisement clicks',
  ));

  // Reset menu, comments and other default options.
  variable_set('menu_options_simpleads', array());
  variable_set('node_options_simpleads', array());
  variable_set('comment_simpleads', 1);
  variable_set('simpleads_display_graphs', 1);
}

/**
 * Implements hook_uninstall().
 */
function simpleads_uninstall() {
  field_delete_field('field_ad_category');
  field_delete_field('field_ad_type');
  field_delete_field('field_ad_image');
  field_delete_field('field_ad_flash');
  field_delete_field('field_ad_text');
  field_delete_field('field_ad_url');
  field_delete_field('field_ad_date');
  node_types_rebuild();
  $vid = db_select('taxonomy_vocabulary', 'tv')
    ->fields('tv', array(
    'vid',
  ))
    ->condition('machine_name', 'simpleads_groups')
    ->execute()
    ->fetchField();
  taxonomy_vocabulary_delete($vid);
  variable_del('menu_options_simpleads');
  variable_del('node_options_simpleads');
  variable_del('comment_simpleads');
  variable_del('simpleads_display_graphs');
}

/**
 * Implements hook_schema().
 */
function simpleads_schema() {
  $schema['simpleads_impressions'] = array(
    'description' => 'Advertisement impressions',
    'fields' => array(
      'aid' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Advertisement ID',
      ),
      'nid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'description' => 'Node ID',
      ),
      'timestamp' => array(
        'type' => 'int',
        'not null' => TRUE,
        'description' => 'Timestamp',
      ),
      'ip_address' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'IP Address',
      ),
      'url' => array(
        'type' => 'text',
        'not null' => FALSE,
        'description' => 'Website URL',
      ),
    ),
    'primary key' => array(
      'aid',
    ),
    'indexes' => array(
      'aid' => array(
        'aid',
      ),
      'nid' => array(
        'nid',
      ),
    ),
  );
  $schema['simpleads_clicks'] = array(
    'description' => 'Advertisement clicks',
    'fields' => array(
      'aid' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Advertisement ID',
      ),
      'nid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'description' => 'Node ID',
      ),
      'timestamp' => array(
        'type' => 'int',
        'not null' => TRUE,
        'description' => 'Timestamp',
      ),
      'ip_address' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'IP address',
      ),
      'url' => array(
        'type' => 'text',
        'not null' => FALSE,
        'description' => 'Website URL',
      ),
    ),
    'primary key' => array(
      'aid',
    ),
    'indexes' => array(
      'aid' => array(
        'aid',
      ),
      'nid' => array(
        'nid',
      ),
    ),
  );
  $schema['simpleads_stats'] = array(
    'description' => 'Advertisement aggregated stats',
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'description' => 'Advertisement node ID',
      ),
      'date' => array(
        'type' => 'int',
        'not null' => FALSE,
        'description' => 'Stats day',
      ),
      'clicks' => array(
        'type' => 'int',
        'not null' => FALSE,
        'description' => 'Clicks counter',
      ),
      'clicks_unique' => array(
        'type' => 'int',
        'not null' => FALSE,
        'description' => 'Clicks counter',
      ),
      'impressions' => array(
        'type' => 'int',
        'not null' => FALSE,
        'description' => 'Impressions counter',
      ),
      'impressions_unique' => array(
        'type' => 'int',
        'not null' => FALSE,
        'description' => 'Impressions counter',
      ),
    ),
    'primary key' => array(
      'nid',
      'date',
    ),
  );
  $schema['simpleads_blocks'] = array(
    'description' => 'Advertisement blocks',
    'fields' => array(
      'bid' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Advertisement block ID',
      ),
      'machine_name' => array(
        'type' => 'varchar',
        'length' => 20,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Block machine name',
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Block administrative name',
      ),
      'view_name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'View name',
      ),
      'view_display_id' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'View display id',
      ),
      'settings' => array(
        'type' => 'text',
        'not null' => TRUE,
        'description' => 'Serialized data (settings)',
      ),
    ),
    'primary key' => array(
      'bid',
    ),
    'indexes' => array(
      'bid' => array(
        'bid',
      ),
    ),
  );
  return $schema;
}

Functions

Namesort descending Description
simpleads_install Implements hook_install().
simpleads_schema Implements hook_schema().
simpleads_uninstall Implements hook_uninstall().