summaryrefslogtreecommitdiff
path: root/kolab.org/www/drupal-7.18/sites/all/modules/socialshareprivacy/socialshareprivacy.install
blob: a889dd00a12ce1709f80265d3ea06299418fff61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php

/**
 * @file
 * Install/uninstall file for socialSharePrivacy module
 */

/**
 * Implement hook_field_schema().
 */
function socialshareprivacy_field_schema($field) {
  $columns = array(
    'value' => array('type' => 'int', 'default' => 0, 'not null' => FALSE),
  );
  return array('columns' => $columns, 'indexes' => array());
}

/**
 * Implements hook_install().
 */
function socialshareprivacy_install() {
  variable_set('socialshareprivacy_field_name', 'field_socialshareprivacy');
  variable_set('socialshareprivacy_field_type', 'ssp_placeholder');
  variable_set('socialshareprivacy_formatter', 'ssp_node_formatter');
  variable_set('socialshareprivacy_widget', 'ssp_widget');
}

/**
 * Implements hook_disable().
 *
 * put an message only.
 */
function socialshareprivacy_disable() {
  drupal_set_message(t('Social share privacy: disabled. The field will remain until uninstalled.'));
}

/**
 * Implements hook_uninstall().
 */
function socialshareprivacy_uninstall() {

  $ssp_field_name = variable_get('socialshareprivacy_field_name');
  if (field_read_field($ssp_field_name)) {
    foreach (node_type_get_names() as $name => $value) {
      __remove_custom_field('node', $name);
    }
    field_delete_field($ssp_field_name); // is needed because of core bug
    field_purge_batch(2000);
  }

  variable_del('socialshareprivacy_services');
  variable_del('socialshareprivacy_services_permaoption');
  variable_del('socialshareprivacy_ext_link');
  variable_del('socialshareprivacy_ext_link_target');
  variable_del('socialshareprivacy_js_minified');
  variable_del('socialshareprivacy_facebook_action');
  variable_del('socialshareprivacy_cookie_expires');
  variable_del('socialshareprivacy_referrertrack');
  variable_del('socialshareprivacy_force_german');
  variable_del('socialshareprivacy_field_name');
  variable_del('socialshareprivacy_formatter');
  variable_del('socialshareprivacy_widget');
  variable_del('socialshareprivacy_field_type');
  variable_del('socialshareprivacy_neutral_button');

  drupal_set_message(t('Social share privacy: deleted field and variables'));
}

/**
 * Implements hook_update_N().
 *
 * Deletes existing socialshareprivacy fields.
 */
function socialshareprivacy_update_7002() {
  $ssp_field_name = 'field_socialshareprivacy';
  // Sets the new variables
  variable_set('socialshareprivacy_field_name', $ssp_field_name);
  variable_set('socialshareprivacy_field_type', 'ssp_placeholder');

  variable_set('socialshareprivacy_formatter', 'ssp_node_formatter');

  variable_set('socialshareprivacy_widget', 'ssp_widget');
  if (field_read_field($ssp_field_name)) {
    foreach (node_type_get_names() as $name => $value) {
      __remove_custom_field('node', $name);
    }
    field_delete_field($ssp_field_name); // is needed because of core bug
    field_purge_batch(2000);
  }
  drupal_set_message(check_plain(t('Please check the new !settingslink field settings.',
      array('!settingslink' => l(t('Social share privacy'), 'admin/config/user-interface/socialshareprivacy/fieldmgmt'))
      )), 'warning'
  );
  return t('Existing socialshareprivacy fields deleted.');
}

function __add_custom_field($entity, $bundle) {

  $t = get_t();
  $ssp_field_name = variable_get('socialshareprivacy_field_name', 'field_socialshareprivacy');
  // Clear the field cache to be sure the new field type is available.
  field_cache_clear();

  if (!field_info_field($ssp_field_name)) {
    $field = array(
      'field_name' => $ssp_field_name,
      'module' => 'socialshareprivacy',
      'no_ui' => TRUE,
      'settings' => array(
        'allowed_values' => array(
          0 => 'hidden',
          1 => 'shown',
        ),
        'allowed_values_function' => '',
      ),
      'type' => SOCIALSHAREPRIVACY_FIELD_TYPE,
    );
    field_create_field($field);
  }

  if (!field_info_instance($entity, $ssp_field_name, $bundle)) {
    $instance = array();
    $instance = array(
      'bundle' => $bundle,
      'default_value' => array(
        0 => array(
          'value' => 1,
        ),
      ),
      'display' => array(
        'default' => array(
          'label' => 'hidden',
          'module' => 'socialshareprivacy',
          'settings' => array(),
          'type' => SOCIALSHAREPRIVACY_FORMATTER,
          'weight' => 20,
        ),
        'teaser' => array(
          'label' => 'hidden',
          'module' => 'socialshareprivacy',
          'settings' => array(),
          'type' => SOCIALSHAREPRIVACY_FORMATTER,
          'weight' => 20,
        ),
      ),
      'entity_type' => $entity,
      'field_name' => $ssp_field_name,
      'label' => $t('Placeholder for Social Share Privacy'),
      'required' => 0,
      'settings' => array(
        'user_register_form' => FALSE,
      ),
      'widget' => array(
        'active' => 1,
        'module' => 'socialshareprivacy',
        'settings' => array(
          'display_label' => 1,
        ),
        'type' => SOCIALSHAREPRIVACY_WIDGET,
        'weight' => 20,
      ),
    );

    field_create_instance($instance);
  }
}

function __remove_custom_field($entity, $bundle) {
  $ssp_field_name = variable_get('socialshareprivacy_field_name', 'field_socialshareprivacy');
  field_cache_clear();
  if ($instance = field_info_instance($entity, $ssp_field_name, $bundle)) {
    field_delete_instance($instance);
    field_purge_batch(2000);
  }
}