You are here

function flickr_block_install in Flickr 7

Implements hook_install().

File

block/flickr_block.install, line 10
The Flickr Block install hook

Code

function flickr_block_install() {
  $t = get_t();
  if (function_exists('taxonomy_vocabulary_machine_name_load') && variable_get('flickr_smart', 0)) {
    $vocab = (object) array(
      'name' => 'Flickr tags',
      'machine_name' => 'flickr_tags',
      'description' => $t('Grab Flickr photos with these tags only. Comma separated. You can exclude results that match a term by prepending it with a - character.'),
    );
    taxonomy_vocabulary_save($vocab);
    $vocabulary = taxonomy_vocabulary_machine_name_load('flickr_tags');
    $field = array(
      'field_name' => 'field_' . $vocabulary->machine_name,
      'type' => 'taxonomy_term_reference',
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
      'settings' => array(
        'allowed_values' => array(
          array(
            'vocabulary' => $vocabulary->machine_name,
            'parent' => 0,
          ),
        ),
      ),
    );
    field_create_field($field);
    $bundles = field_info_bundles($entity_type = 'node');
    foreach ($bundles as $bundle => $value) {
      $instance = array(
        'field_name' => 'field_' . $vocabulary->machine_name,
        'entity_type' => 'node',
        'label' => $vocabulary->name,
        'bundle' => $bundle,
        'description' => $vocabulary->description,
        // Use the taxonomy autocomplete widget.
        'widget' => array(
          'type' => 'taxonomy_autocomplete',
          'weight' => 4,
        ),
        // Define how the terms will be displayed in full node and teaser mode.
        'display' => array(
          'default' => array(
            'label' => 'inline',
            'type' => 'taxonomy_term_reference_link',
            'weight' => 10,
          ),
          'teaser' => array(
            'type' => 'hidden',
            'weight' => 10,
          ),
        ),
      );
      field_create_instance($instance);
    }
    $bundles = field_info_bundles($entity_type = 'user');
    foreach ($bundles as $bundle => $value) {
      $instance = array(
        'field_name' => 'field_' . $vocabulary->machine_name,
        'entity_type' => 'user',
        'label' => $vocabulary->name,
        'bundle' => $bundle,
        'description' => $t("Limited the photos used from your Flickr account in Flickr blocks to those having a Flickr tag as indicated here (e.g. 'website' or 'blog'). Those have to be added to individual photos on Flickr as well. This is not necessary if the Flickr blocks themselves make use of the Flickr tags attached to a post, as the grabbed photos are filtered by those already. To do the opposite, exclude results that match a term by prepending it with a - character.<br />NOTA BENE: Does NOT have any impact on the photos displayed in a user profile."),
        // Use the taxonomy autocomplete widget.
        'widget' => array(
          'type' => 'taxonomy_autocomplete',
          'weight' => 4,
        ),
        // Define how the terms will be displayed on the user profile.
        'display' => array(
          'default' => array(
            'type' => 'hidden',
            'weight' => 10,
          ),
        ),
      );
      field_create_instance($instance);
    }
    foreach (range(0, 16) as $delta) {
      variable_set('flickr_block_' . $delta, array(
        'vocab' => $vocabulary->vid,
      ));
    }
  }
  if (module_exists('date') && module_exists('date_popup') && variable_get('flickr_smart', 0)) {
    $field = array(
      'field_name' => 'field_flickr_date',
      'type' => 'datetime',
      'cardinality' => 1,
      'settings' => array(
        'repeat' => 0,
        'todate' => 'optional',
        'granularity' => array(
          'year' => 'year',
          'month' => 'month',
          'day' => 'day',
        ),
        'tz_handling' => 'none',
        'timezone_db' => '',
        'cache_enabled' => 1,
        'cache_count' => 2,
      ),
    );
    field_create_field($field);
    $bundles = field_info_bundles($entity_type = 'node');
    foreach ($bundles as $bundle => $value) {
      $instance = array(
        'field_name' => 'field_flickr_date',
        'entity_type' => 'node',
        'label' => $t('Flickr date taken'),
        'bundle' => $bundle,
        'description' => $t('Grab Flickr photos taken on or between these dates only.'),
        'widget' => array(
          'type' => 'date_popup',
          'weight' => 5,
          'settings' => array(
            'input_format' => 'Y-m-d H:i:s',
            'year_range' => '-100:+1',
            'increment' => 1,
          ),
        ),
        // Define how the terms will be displayed in full node and teaser mode.
        'display' => array(
          'default' => array(
            'type' => 'date_default',
            'format_type' => 'long',
            'settings' => array(
              'format_type' => 'long',
              'show_repeat_rule' => 'show',
              'multiple_number' => '',
              'multiple_from' => '',
              'multiple_to' => '',
              'fromto' => 'both',
            ),
          ),
          'teaser' => array(
            'type' => 'hidden',
            'weight' => 10,
          ),
        ),
        'settings' => array(
          'default_value' => 'blank',
          'default_value2' => 'blank',
        ),
      );
      field_create_instance($instance);
    }
    if (isset($vocabulary)) {
      foreach (range(0, 16) as $delta) {
        variable_set('flickr_block_' . $delta, array(
          'vocab' => $vocabulary->vid,
          'date' => 'field_flickr_date',
        ));
      }
    }
    else {
      foreach (range(0, 16) as $delta) {
        variable_set('flickr_block_' . $delta, array(
          'date' => 'field_flickr_date',
        ));
      }
    }
  }
  if (module_exists('geofield') && variable_get('flickr_smart', 0)) {
    $field = array(
      'translatable' => '0',
      'settings' => array(
        'backend' => 'default',
        'srid' => '4326',
      ),
      'field_name' => 'field_flickr_geo',
      'type' => 'geofield',
      'active' => '1',
      'locked' => '0',
      'cardinality' => '1',
    );
    field_create_field($field);
    $bundles = field_info_bundles($entity_type = 'node');
    foreach ($bundles as $bundle => $value) {
      $instance = array(
        'field_name' => 'field_flickr_geo',
        'entity_type' => 'node',
        'label' => $t('Flickr location'),
        'bundle' => $bundle,
        'description' => $t('Grab Flickr photos near this location only.'),
        'required' => 0,
        'default_value' => NULL,
        'widget' => array(
          'weight' => '6',
          'type' => 'geofield_latlon',
          'active' => 1,
          'settings' => array(
            'html5_geolocation' => 0,
          ),
        ),
        // Define how the terms will be displayed in full node and teaser mode.
        'display' => array(
          'default' => array(
            'label' => 'above',
            'type' => 'geofield_description',
            'weight' => '13',
            'settings' => array(
              'data' => 'centroid',
              'address' => 1,
            ),
          ),
          'teaser' => array(
            'type' => 'hidden',
            'label' => 'above',
            'settings' => array(),
            'weight' => 0,
          ),
        ),
      );
      field_create_instance($instance);
    }
    if (isset($vocabulary) && module_exists('date') && module_exists('date_popup')) {
      foreach (range(0, 16) as $delta) {
        variable_set('flickr_block_' . $delta, array(
          'vocab' => $vocabulary->vid,
          'date' => 'field_flickr_date',
          'geo' => 'field_flickr_geo',
        ));
      }
    }
    elseif (module_exists('date') && module_exists('date_popup')) {
      foreach (range(0, 16) as $delta) {
        variable_set('flickr_block_' . $delta, array(
          'date' => 'field_flickr_date',
          'geo' => 'field_flickr_geo',
        ));
      }
    }
    else {
      foreach (range(0, 16) as $delta) {
        variable_set('flickr_block_' . $delta, array(
          'geo' => 'field_flickr_geo',
        ));
      }
    }
  }

  // We create the variable used to detect if the module has not been
  // uninstalled elsewhere. This variable should exist right away.
  variable_set('flickr_block_photos_per_set', 6);
}