summaryrefslogtreecommitdiff
path: root/kolab.org/www/drupal-7.18/sites/all/modules/socialshareprivacy/socialshareprivacy.admin.inc
blob: 43e80bc56f6b5fc03386c8a053b96fc758f3abdb (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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<?php
/**
 * @file
 * Administration settings form area for Social Share Privacy module
 */

require_once(drupal_get_path('module', 'socialshareprivacy') . '/socialshareprivacy.install');

 /**
 * General configuration form for controlling the behaviour.
 */
function socialshareprivacy_admin_settings() {
    $form = array();

    $socialshareprivacy_path = _socialshareprivacy_get_path();

    $form['socialshareprivacy_path'] = array(
      '#type' => 'textfield',
      '#title' => t('Path'),
      '#default_value' => $socialshareprivacy_path,
      '#description' => t('The location the socialSharePrivacy plugin is installed in. Use a path relative to the Drupal root directory.'),
      '#after_build' => array('_socialshareprivacy_admin_settings_check_plugin_path'),
    );

    $form['socialshareprivacy_services'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Enabled services'),
        '#default_value' => variable_get('socialshareprivacy_services', unserialize(SOCIALSHAREPRIVACY_DEFAULT_VALUE_SERVICES)),
        '#options' => array(
            'facebook' => 'Facebook',
            'twitter' => 'Twitter',
            'gplus' => 'Google+',
        ),
    );

    $form['socialshareprivacy_services_permaoption'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Enabled permanent options'),
        '#description' => t('Enabling this option for a social network means that the user gets an option to enable permanent data transfer to the corresponding network, thus reverting to the non-privacy 1-click sharing workflow.'),
        '#default_value' => variable_get('socialshareprivacy_services_permaoption', unserialize(SOCIALSHAREPRIVACY_DEFAULT_VALUE_SERVICES)),
        '#options' => array(
            'facebook' => 'Facebook',
            'twitter' => 'Twitter',
            'gplus' => 'Google+',
        ),
    );

    $form['socialshareprivacy_facebook_action'] = array(
      '#type' => 'radios',
      '#title' => t('Facebook button action'),
      '#options' => array(
        'recommend' => t('Recommend'),
        'like' => t('Like'),
      ),
      '#default_value' => variable_get('socialshareprivacy_facebook_action', 'recommend'),
    );

    $form['socialshareprivacy_ext_link'] = array(
      '#type' => 'radios',
      '#title' => t('External link (info icon)'),
      '#default_value' => variable_get('socialshareprivacy_ext_link', ''),
      '#options' => array(
        '' => t('Open the link in the current window.'),
        'blank' => t('Open the link in a new window.'),
        'remove' => t('Remove the click event of the link.'),
      ),
    );

    $form['socialshareprivacy_ext_link_target'] = array(
      '#type' => 'textfield',
      '#title' => t('Change default info link'),
      '#description' => t('If you do not want the info icon to link to the original explanatory page at heise.de you can override the target by specifying a URL here.'),
      '#default_value' => variable_get('socialshareprivacy_ext_link_target', 'http://www.heise.de/ct/artikel/2-Klicks-fuer-mehr-Datenschutz-1333879.html'),
    );

    $form['socialshareprivacy_js_minified'] = array(
      '#type' => 'radios',
      '#title' => t('Use minified javascript file'),
      '#options' => array(
        'true' => t('Yes'),
        'false' => t('No'),
      ),
      '#default_value' => variable_get('socialshareprivacy_js_minified', 'true'),
    );

    $form['socialshareprivacy_reset_css'] = array(
      '#type' => 'radios',
      '#title' => t('Include reset.css'),
      '#options' => array(
        'true' => t('Yes'),
        'false' => t('No'),
      ),
      '#default_value' => variable_get('socialshareprivacy_reset_css', 'false'),
    );

    $form['socialshareprivacy_force_german'] = array(
      '#type' => 'radios',
      '#title' => t('Ignore Drupal\'s translations and use the original German texts from the plugin.'),
      '#options' => array(
        'true' => t('Yes'),
        'false' => t('No'),
      ),
      '#default_value' => variable_get('socialshareprivacy_force_german', 'false'),
    );

    $form['socialshareprivacy_neutral_button'] = array(
      '#type' => 'radios',
      '#title' => t('Use language-neutral Facebook button'),
      '#options' => array(
        'true' => t('Yes'),
        'false' => t('No'),
      ),
      '#default_value' => variable_get('socialshareprivacy_neutral_button', 'false'),
    );

    $form['socialshareprivacy_cookie_expires'] = array(
      '#type' => 'textfield',
      '#title' => t('Cookie expiration time'),
      '#description' => t('Cookie expiration time in days.'),
      '#default_value' => variable_get('socialshareprivacy_cookie_expires', '365'),
    );

    $form['socialshareprivacy_referrertrack'] = array(
      '#type' => 'textfield',
      '#title' => t('Tracking parameter'),
      '#description' => t('The tracking parameter will be added to the end of the URL which is useful for tracking the referrer.'),
      '#default_value' => variable_get('socialshareprivacy_referrertrack', ''),
    );

    return system_settings_form($form);
}

function socialshareprivacy_admin_fieldmgmt() {

  if (!module_exists('field_ui')) {
    drupal_set_message(t('Enable the Field UI module to adjust the Social Share Privacy field settings, manage node fields or manage the display.'), 'warning');
  }

    $ret[] = array('#markup' => t('Enable/Disable the Socialshareprivacy field for your content types (disabling will delete the data for all nodes of the content type):<br/>'));
    $ret[] = drupal_get_form('socialshareprivacy_form_admin_fieldmgmt');
    return $ret;
}

function socialshareprivacy_form_admin_fieldmgmt($form, &$form_state) {
    $form = array();

    $head = array(
      'contenttype' => array('data' => t('Content types'), 'field' => 'contenttype'),
    );

    $options = array();
    $default_values = array();
    foreach (node_type_get_names() as $name => $value) {
      $options['ssp_fieldmgmt_' . $name] = array(
        'contenttype' => array(
          'data' => array(
            '#type' => 'link',
            '#title' => $value,
            '#href' => 'admin/structure/types/manage/' . $name . '/fields',
          ),
        ),
      );
      $is_enabled = 0;
      if (field_info_instance('node', variable_get('socialshareprivacy_field_name'), $name)) {
        $is_enabled = 1;
      }
      $default_values['ssp_fieldmgmt_' . $name] = $is_enabled;
    }

    $form['ssp_fieldmgmt'] = array(
      '#type' => 'tableselect',
      '#header' => $head,
      '#options' => $options,
      '#default_value' => $default_values,
      '#empty' => t('No content available.'),
    );

    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save'),
    );

    return $form;
}

function socialshareprivacy_form_admin_fieldmgmt_submit($form, &$form_state) {
  $form_values =  $form_state['values'];
  $ssp_fieldmgmt = $form_values['ssp_fieldmgmt'];
  $entity = 'node';
  foreach ($ssp_fieldmgmt as $k => $v) {
    if ($v===0) { // this means checked ..
      __remove_custom_field($entity, drupal_substr($k, 14));
    }
    else {
      __add_custom_field($entity, drupal_substr($k, 14));
    }
  }

  drupal_set_message(t('The configuration options have been saved.'));
}

function socialshareprivacy_admin_bulkupdate() {

    $ret[] = array('#markup' => t('Update the Socialshareprivacy boolean for existing nodes:<br/>Nothing to select? !url.<br/>', array('!url' => l(t('Enable a content type'), 'admin/config/user-interface/socialshareprivacy/fieldmgmt'))));
    $ret[] = drupal_get_form('socialshareprivacy_form_admin_bulk');
    return $ret;
}

function socialshareprivacy_form_admin_bulk($form, &$form_state) {
    $form = array();

    $head = array(
      'contenttype' => array('data' => t('Content types'), 'field' => 'contenttype'),
    );

    $options = array();
    $options['none'] = 'none';
    foreach (node_type_get_names() as $name => $value) {
      if (field_info_instance('node', variable_get('socialshareprivacy_field_name'), $name)) {
        $options[$name] = $value;
      }
    }

    $form['ssp_bulkupdate_type'] = array(
      '#type' => 'select',
      '#title' => t('Please choose a content type'),
      '#options' => $options,
      '#default_value' => 'none',
    );

    $options = array();
    $options[LANGUAGE_NONE] = t('Undetermined');
    foreach (language_list() as $obj) {
      $options[$obj->language] = $obj->native;
    }
    $form['ssp_bulkupdate_langs'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Please choose the desired languages'),
      '#options' => $options,
    );

    $form['ssp_bulkupdate_value'] = array(
      '#type' => 'checkbox',
      '#title' => t('Enable SSP'),
      '#description' => t('If this box is checked then SSP will be enabled on the chosen nodes, otherwise it will be disabled.'),
    );

    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Update'),
    );

    return $form;
}

function socialshareprivacy_form_admin_bulk_submit($form, &$form_state) {
  $form_values =  $form_state['values'];
  $contenttype = $form_values['ssp_bulkupdate_type'];
  $valuetoset = $form_values['ssp_bulkupdate_value'];
  if ($valuetoset=='') {
    $valuetoset = '0';
  }
  $lang_choosen = FALSE;
  $langs = $form_values['ssp_bulkupdate_langs'];
  foreach ($langs as $lang => $value) {
    if ($lang==$value) {
      $lang_choosen = TRUE;
    }
  }

  if ($contenttype!='none' && $lang_choosen) {
    $node_type = 'page'; // Machine name of the content type
    $entity = 'node';

    $query = new EntityFieldQuery;
    $result = $query
      ->entityCondition('entity_type', $entity)
      ->propertyCondition('type', $contenttype)
      ->execute();

    if (!empty($result['node'])) {
      $nodes = entity_load('node', array_keys($result['node']));

      foreach ($nodes as $node) {
        foreach ($langs as $lang => $value) {
          if ($lang == $value) {
            $node->field_socialshareprivacy[$lang][0]['value'] = $valuetoset;
          }
        }
        node_save($node);
      }
    }
    drupal_set_message(t('The nodes of type "@contenttype" have been updated.', array('@contenttype' => $contenttype)));
  }
  else {
    if ($contenttype=='none') {
    drupal_set_message(t('Please choose a content type.'), 'error');
    }

    if (!$lang_choosen) {
      drupal_set_message(t('Please choose at least one language.'), 'error');
    }
  }
}