Projet

Général

Profil

Paste
Télécharger (4,07 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / token_insert / token_insert.module @ c169e7c4

1
<?php
2
/**
3
 * @file
4
 * wysiwyg plugin hook.
5
 */
6

    
7
function token_insert_permission() {
8
  return array(
9
      'administer token insert settings' => array(
10
          'title' => t('administer token insert settings'),
11
          'description' => t('Administer token insert settings')),
12
      'use token insert' => array(
13
          'title' => t('use token insert'),
14
          'description' => t('Allows user to use the token insert module')),
15
      );
16
}
17

    
18
function token_insert_menu() {
19
  
20
  $items['admin/config/content/token_insert'] = array(
21
    'title' => 'Token insert',
22
    'description' => 'Change the token users can insert.',
23
    'type' => MENU_NORMAL_ITEM,
24
    'page callback' => 'drupal_get_form',
25
    'page arguments' => array('token_insert_settings_form'),
26
    'access arguments' => array('administer token insert settings'),
27
  );
28
  
29
  return $items;
30
}
31

    
32
function token_insert_settings_form($form_state) {
33
  $form = array();
34
  $form['tokens'] = array(
35
      '#type' => 'vertical_tabs',
36
  );
37
  $form['tokens_per_role'] = array(
38
      '#type' => 'fieldset',
39
      '#title' => t('Token Insert per role'),
40
      '#description' => t('Configure available tokens per user role'),
41
      '#collapsible' => FALSE,
42
  );
43

    
44
  $form['tokens_per_role']['token_insert_use_tokens_per_role'] = array(
45
      '#type' => 'checkbox',
46
      '#title' => t('Use tokens per role'),
47
      '#default_value' => variable_get('token_insert_use_tokens_per_role', 0),
48
  );
49

    
50
  $roles ['global'] = 'global';
51
  if(variable_get('token_insert_use_tokens_per_role', 0)){
52
    $roles += user_roles(TRUE, 'use token insert');
53
  }
54
  $all_tokens = token_get_info();
55

    
56
  foreach($roles as $rid => $role){
57
    $title = t("Available tokens for $role");
58
    $description = t("Available tokens for users with the '$role' role");
59
    if($rid == 'global'){
60
      $title = t('Globally available tokens');
61
      $description = t('Tokens available for every user');
62
    }
63
    $form[$rid . '_available_tokens'] = array(
64
      '#type' => 'fieldset',
65
      '#title' => $title,
66
      '#description' => $description,
67
      '#collapsible' => TRUE,
68
      '#collapsed' => TRUE,
69
    );
70
    foreach ($all_tokens['tokens'] as $category => $tokens) {
71

    
72
      $form[$rid . '_available_tokens'][$category] = array(
73
        '#type' => 'fieldset',
74
        '#title' => t($category),
75
        '#collapsible' => TRUE,
76
        '#collapsed' => TRUE,
77
      );
78

    
79
      $options = array();
80
      $defaults = array();
81

    
82
      foreach ($tokens as $token => $description) {
83
        $options[$token] = $category . ' : [' . $token . '] : ' . t($description['description']);
84
        $defaults[$token] = 0;
85
      }
86

    
87

    
88
      $form[$rid . '_available_tokens'][$category]['token_insert_' . $rid . '_used_tokens_' . $category] = array(
89
        '#type' => 'checkboxes',
90
        '#title' => t('Select tokens'),
91
        '#default_value' => variable_get('token_insert_' . $rid . '_used_tokens_' . $category, array()),
92
        '#options' => $options,
93
        '#description' => t('Select ' . $category . ' tokens available for insert.')
94
      );
95
    }
96
  }
97
  
98
  return system_settings_form($form);
99
}
100

    
101
function token_insert_help($path, $arg){
102
  if($path == 'admin/help#token_insert'){
103
    $output = <<<EOT
104
    <h3>Description</h3>
105
    <p>This module allows you to insert tokens into a textarea. It supports both plain text and wysiwyg textareas. The format used for the insert is compatible with Token filter.</p>
106
    <p>This module contains three modules:</p>
107
    <ul>
108
      <li>Token insert UI: Allows you to select which tokens are available for the insert, by default all tokens are shown. This module doesn't have to be enabled to use the others.</li>
109
      <li>Token insert (text): Add a fieldset under each textarea, works for both plain text fields and wysiwyg fields.</li>
110
      <li>Token insert (wysiwyg): Adds an extra button to wysiwyg editors and opens a popup to select the token to insert.</li>
111
    </ul>
112
    <h3>Dependencies</h3>
113
    <ul>
114
      <li>Token</li>
115
    </ul>
116
    <h3>Recommended</h3>
117
    <ul>
118
      <li>Token filter</li>
119
    </ul>
120
    <h3>Thanks to</h3>
121
    <ul>
122
      <li>Attiks</li>
123
      <li>Jelle</li>
124
    </ul>
125
EOT;
126
  return $output;
127
  }
128

    
129
}