Completed
Push — master ( 6e38a6...4ed690 )
by Christian
10:37
created
modules/contrib/privatemsg/privatemsg_filter/privatemsg_filter.admin.inc 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -9,39 +9,39 @@  discard block
 block discarded – undo
9 9
  * Display a list of tags to administer them.
10 10
  */
11 11
 function privatemsg_tags_admin() {
12
-  drupal_set_title(t('Tags'));
12
+    drupal_set_title(t('Tags'));
13 13
 
14
-  $header = array(
14
+    $header = array(
15 15
     'tag' => array(
16
-      'data'    => t('Tag'),
17
-      'field'   => 'tag',
18
-      'class'   => 'privatemsg-filter-header-tag',
19
-      'sort'    => 'asc',
20
-      '#weight' => -40,
16
+        'data'    => t('Tag'),
17
+        'field'   => 'tag',
18
+        'class'   => 'privatemsg-filter-header-tag',
19
+        'sort'    => 'asc',
20
+        '#weight' => -40,
21 21
     ),
22 22
     'usage' => array(
23
-      'data'    => t('Usage'),
24
-      'field'   => 'count',
25
-      'class'   => 'privatemsg-filter-header-usage',
26
-      '#weight' => -30,
23
+        'data'    => t('Usage'),
24
+        'field'   => 'count',
25
+        'class'   => 'privatemsg-filter-header-usage',
26
+        '#weight' => -30,
27 27
     ),
28 28
     'public' => array(
29
-      'data'    => t('Public'),
30
-      'field'   => 'public',
31
-      'class'   => 'privatemsg-filter-header-public',
32
-      '#weight' => -20,
29
+        'data'    => t('Public'),
30
+        'field'   => 'public',
31
+        'class'   => 'privatemsg-filter-header-public',
32
+        '#weight' => -20,
33 33
     ),
34 34
     'operations' => array(
35
-      'data'    => t('Operations'),
36
-      'class'   => 'privatemsg-filter-header-operations',
37
-      '#weight' => -10,
35
+        'data'    => t('Operations'),
36
+        'class'   => 'privatemsg-filter-header-operations',
37
+        '#weight' => -10,
38 38
     ),
39
-  );
40
-  $query = _privatemsg_assemble_query(array('tags', 'privatemsg_filter'));
41
-  $result = pager_query($query['query'] . tablesort_sql($header), 100);
39
+    );
40
+    $query = _privatemsg_assemble_query(array('tags', 'privatemsg_filter'));
41
+    $result = pager_query($query['query'] . tablesort_sql($header), 100);
42 42
 
43
-  $rows = array();
44
-  while ($tag = db_fetch_array($result)) {
43
+    $rows = array();
44
+    while ($tag = db_fetch_array($result)) {
45 45
     $row = array();
46 46
     $row['tag'] = check_plain($tag['tag']);
47 47
     $row['count'] = $tag['count'];
@@ -50,14 +50,14 @@  discard block
 block discarded – undo
50 50
     $row['operations'] .= ' ' . l(t('delete'), 'admin/settings/messages/tags/delete/' . $tag['tag_id']);
51 51
 
52 52
     $rows[] = $row;
53
-  }
53
+    }
54 54
 
55
-  if (empty($rows)) {
55
+    if (empty($rows)) {
56 56
     // Display a message if now tags are available.
57 57
     $rows[] = array(array('data' => t('No tags available.'), 'colspan' => count($header)));
58
-  }
58
+    }
59 59
 
60
-  return theme('table', $header, $rows) . theme('pager');
60
+    return theme('table', $header, $rows) . theme('pager');
61 61
 }
62 62
 
63 63
 /**
@@ -70,36 +70,36 @@  discard block
 block discarded – undo
70 70
  *   new tag form.
71 71
  */
72 72
 function privatemsg_tags_form(&$form_state, $tag_id = NULL) {
73
-  $form = array();
73
+    $form = array();
74 74
 
75
-  if ($tag_id) {
75
+    if ($tag_id) {
76 76
     $tag = db_fetch_array(db_query('SELECT * from {pm_tags} pmt WHERE pmt.tag_id = %d', $tag_id));
77 77
     $form['tag_id'] = array(
78
-      '#value' => $tag_id,
79
-      '#type' => 'value',
78
+        '#value' => $tag_id,
79
+        '#type' => 'value',
80 80
     );
81 81
     drupal_set_title(t('Edit @tag', array('@tag' => $tag['tag'])));
82
-  }
82
+    }
83 83
 
84
-  $form['tag'] = array(
84
+    $form['tag'] = array(
85 85
     '#title' => t('Name'),
86 86
     '#type' => 'textfield',
87 87
     '#default_value' => empty($tag_id) ? NULL : $tag['tag'],
88
-  );
88
+    );
89 89
 
90
-  $form['public'] = array(
90
+    $form['public'] = array(
91 91
     '#title' => t('Public'),
92 92
     '#type' => 'checkbox',
93 93
     '#default_value' => empty($tag_id) ? TRUE : $tag['public'],
94 94
     '#description' => t('Public tags are visible for all users, private tags are only visible if they use them.'),
95
-  );
95
+    );
96 96
 
97
-  $form['submit'] = array(
97
+    $form['submit'] = array(
98 98
     '#value' => empty($tag_id) ? t('Create tag') : t('Save tag'),
99 99
     '#type'  => 'submit',
100
-  );
100
+    );
101 101
 
102
-  return $form;
102
+    return $form;
103 103
 }
104 104
 
105 105
 /**
@@ -108,34 +108,34 @@  discard block
 block discarded – undo
108 108
  * Make sure that a tag name is unique.
109 109
  */
110 110
 function privatemsg_tags_form_validate($form, &$form_state) {
111
-  $tag_id = isset($form_state['values']['tag_id']) ? $form_state['values']['tag_id'] : 0;
112
-  if ($tag_id) {
111
+    $tag_id = isset($form_state['values']['tag_id']) ? $form_state['values']['tag_id'] : 0;
112
+    if ($tag_id) {
113 113
     // We are editing an existing tag, exclude the current tag from the search.
114 114
     $exists = db_result(db_query("SELECT 1 FROM {pm_tags} WHERE tag = '%s' AND tag_id <> %d", $form_state['values']['tag'], $tag_id));
115
-  }
116
-  else {
115
+    }
116
+    else {
117 117
     $exists = db_result(db_query("SELECT 1 FROM {pm_tags} WHERE tag = '%s'", $form_state['values']['tag']));
118
-  }
119
-  if ($exists) {
118
+    }
119
+    if ($exists) {
120 120
     form_set_error('tag', t('Tag already exists, choose a different name.'));
121
-  }
121
+    }
122 122
 }
123 123
 
124 124
 /**
125 125
  * Form submit handler for add/edit forms.
126 126
  */
127 127
 function privatemsg_tags_form_submit($form, &$form_state) {
128
-  if (!empty($form_state['values']['tag_id'])) {
128
+    if (!empty($form_state['values']['tag_id'])) {
129 129
     // Tag already exists, update the existing tag.
130 130
     db_query("UPDATE {pm_tags} SET tag = '%s', public = %d WHERE tag_id = %d", $form_state['values']['tag'], $form_state['values']['public'], $form_state['values']['tag_id']);
131 131
     drupal_set_message(t('Tag updated.'));
132 132
     $form_state['redirect'] = 'admin/settings/messages/tags';
133
-  }
134
-  else {
133
+    }
134
+    else {
135 135
     // Tag does not yet exist, create a new one.
136 136
     db_query("INSERT INTO {pm_tags} (tag, public) VALUES ('%s', %d)", $form_state['values']['tag'], $form_state['values']['public']);
137 137
     drupal_set_message(t('Tag created.'));
138
-  }
138
+    }
139 139
 }
140 140
 
141 141
 /**
@@ -145,28 +145,28 @@  discard block
 block discarded – undo
145 145
  *   Id of the tag that should be deleted.
146 146
  */
147 147
 function privatemsg_filter_tags_delete(&$form_state, $tag_id) {
148
-  $form['tag_id'] = array(
148
+    $form['tag_id'] = array(
149 149
     '#type' => 'value',
150 150
     '#value' => $tag_id,
151
-  );
152
-  return confirm_form($form,
151
+    );
152
+    return confirm_form($form,
153 153
     t('Are you sure you want to delete?'),
154 154
     isset($_GET['destination']) ? $_GET['destination'] : 'admin/settings/messages/tags',
155 155
     t('This action cannot be undone.'),
156 156
     t('Delete'),
157 157
     t('Cancel')
158
-  );
158
+    );
159 159
 }
160 160
 
161 161
 /**
162 162
  * Submit handler for the confirm delete form.
163 163
  */
164 164
 function privatemsg_filter_tags_delete_submit($form, &$form_state) {
165
-  if ($form_state['values']['confirm']) {
165
+    if ($form_state['values']['confirm']) {
166 166
     db_query('DELETE FROM {pm_tags} WHERE tag_id = %d', $form_state['values']['tag_id']);
167 167
     db_query('DELETE FROM {pm_tags_index} WHERE tag_id = %d', $form_state['values']['tag_id']);
168 168
 
169 169
     drupal_set_message(t('Tag has been deleted'));
170
-  }
171
-  $form_state['redirect'] = 'admin/settings/messages/tags';
170
+    }
171
+    $form_state['redirect'] = 'admin/settings/messages/tags';
172 172
 }
173 173
\ No newline at end of file
Please login to merge, or discard this patch.
boinc/modules/contrib/privatemsg/privatemsg_filter/privatemsg_filter.module 1 patch
Indentation   +314 added lines, -314 removed lines patch added patch discarded remove patch
@@ -9,34 +9,34 @@  discard block
 block discarded – undo
9 9
  * Implements hook_perm().
10 10
  */
11 11
 function privatemsg_filter_perm() {
12
-  return array(
12
+    return array(
13 13
     'filter private messages',
14 14
     'tag private messages',
15 15
     'create private message tags',
16
-  );
16
+    );
17 17
 }
18 18
 
19 19
 /**
20 20
  * Implements hook_menu().
21 21
  */
22 22
 function privatemsg_filter_menu() {
23
-  $items['admin/settings/messages/filter'] = array(
23
+    $items['admin/settings/messages/filter'] = array(
24 24
     'title'            => 'Filter',
25 25
     'description'      => 'Configure filter settings.',
26 26
     'page callback'    => 'drupal_get_form',
27 27
     'page arguments'   => array('privatemsg_filter_admin'),
28 28
     'access arguments' => array('administer privatemsg settings'),
29 29
     'type'             => MENU_LOCAL_TASK,
30
-  );
31
-  $items['admin/settings/messages/tags'] = array(
30
+    );
31
+    $items['admin/settings/messages/tags'] = array(
32 32
     'title'            => 'Tags',
33 33
     'description'      => 'Configure tags.',
34 34
     'page callback'    => 'privatemsg_tags_admin',
35 35
     'access arguments' => array('administer privatemsg settings'),
36 36
     'type'             => MENU_LOCAL_TASK,
37 37
     'file'             => 'privatemsg_filter.admin.inc',
38
-  );
39
-  $items['admin/settings/messages/tags/list'] = array(
38
+    );
39
+    $items['admin/settings/messages/tags/list'] = array(
40 40
     'title'            => 'List',
41 41
     'description'      => 'Configure tags.',
42 42
     'page callback'    => 'privatemsg_tags_admin',
@@ -44,8 +44,8 @@  discard block
 block discarded – undo
44 44
     'type'             => MENU_DEFAULT_LOCAL_TASK,
45 45
     'file'             => 'privatemsg_filter.admin.inc',
46 46
     'weight'           => -10,
47
-  );
48
-  $items['admin/settings/messages/tags/add'] = array(
47
+    );
48
+    $items['admin/settings/messages/tags/add'] = array(
49 49
     'title'            => 'Add',
50 50
     'description'      => 'Configure tags.',
51 51
     'page callback'    => 'drupal_get_form',
@@ -53,8 +53,8 @@  discard block
 block discarded – undo
53 53
     'access arguments' => array('administer privatemsg settings'),
54 54
     'type'             => MENU_LOCAL_TASK,
55 55
     'file'             => 'privatemsg_filter.admin.inc',
56
-  );
57
-  $items['admin/settings/messages/tags/edit/%'] = array(
56
+    );
57
+    $items['admin/settings/messages/tags/edit/%'] = array(
58 58
     'title'            => 'Add',
59 59
     'description'      => 'Configure tags.',
60 60
     'page callback'    => 'drupal_get_form',
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
62 62
     'access arguments' => array('administer privatemsg settings'),
63 63
     'type'             => MENU_CALLBACK,
64 64
     'file'             => 'privatemsg_filter.admin.inc',
65
-  );
66
-  $items['admin/settings/messages/tags/delete/%'] = array(
65
+    );
66
+    $items['admin/settings/messages/tags/delete/%'] = array(
67 67
     'title'            => 'Add',
68 68
     'description'      => 'Configure tags.',
69 69
     'page callback'    => 'drupal_get_form',
@@ -71,62 +71,62 @@  discard block
 block discarded – undo
71 71
     'access arguments' => array('administer privatemsg settings'),
72 72
     'type'             => MENU_CALLBACK,
73 73
     'file'             => 'privatemsg_filter.admin.inc',
74
-  );
75
-  $items['messages/inbox'] = array(
74
+    );
75
+    $items['messages/inbox'] = array(
76 76
     'title'            => 'Inbox',
77 77
     'page callback'    => 'drupal_get_form',
78 78
     'page arguments'   => array('privatemsg_list', 'inbox'),
79 79
     'access callback'  => 'privatemsg_user_access',
80 80
     'type'             => variable_get('privatemsg_filter_default_list', 0) ? MENU_LOCAL_TASK : MENU_DEFAULT_LOCAL_TASK,
81 81
     'weight'           => -15,
82
-  );
83
-  $items['messages/sent'] = array(
82
+    );
83
+    $items['messages/sent'] = array(
84 84
     'title'            => 'Sent messages',
85 85
     'page callback'    => 'drupal_get_form',
86 86
     'page arguments'   => array('privatemsg_list', 'sent'),
87 87
     'access callback'  => 'privatemsg_user_access',
88 88
     'type'             => MENU_LOCAL_TASK,
89 89
     'weight'           => -12,
90
-  );
91
-  $items['messages/filter/user-name-autocomplete'] = array(
90
+    );
91
+    $items['messages/filter/user-name-autocomplete'] = array(
92 92
     'page callback'    => 'privatemsg_user_name_autocomplete',
93 93
     'access callback'  => 'privatemsg_user_access',
94 94
     'access arguments' => array('write privatemsg'),
95 95
     'type'             => MENU_CALLBACK,
96
-  );
97
-  $items['messages/filter/tag-autocomplete'] = array(
96
+    );
97
+    $items['messages/filter/tag-autocomplete'] = array(
98 98
     'page callback'    => 'privatemsg_filter_tags_autocomplete',
99 99
     'access callback'  => 'privatemsg_user_access',
100 100
     'access arguments' => array('tag private messages'),
101 101
     'type'             => MENU_CALLBACK,
102 102
     'weight'           => -10,
103
-  );
104
-  return $items;
103
+    );
104
+    return $items;
105 105
 }
106 106
 
107 107
 /**
108 108
  * Implements hook_menu_alter().
109 109
  */
110 110
 function privatemsg_filter_menu_alter(&$items) {
111
-  // Rename messages to "All messages".
112
-  $items['messages/list']['title'] = 'All messages';
111
+    // Rename messages to "All messages".
112
+    $items['messages/list']['title'] = 'All messages';
113 113
 
114
-  if (variable_get('privatemsg_filter_default_list', 0) == 0) {
114
+    if (variable_get('privatemsg_filter_default_list', 0) == 0) {
115 115
     // Change default argument of /messages to inbox. and set the task to MENU_LOCAL_TASK.
116 116
     $items['messages']['page arguments'] = array('privatemsg_list', 'inbox');
117 117
     $items['messages/list']['type'] = MENU_LOCAL_TASK;
118
-  }
118
+    }
119 119
 }
120 120
 
121 121
 function privatemsg_filter_admin() {
122
-  $form = array();
122
+    $form = array();
123 123
 
124
-  $form['privatemsg_filter_searchbody'] = array(
124
+    $form['privatemsg_filter_searchbody'] = array(
125 125
     '#type'          => 'checkbox',
126 126
     '#title'         => t('Search message body'),
127 127
     '#description'   => t('WARNING: turning on this feature will slow down search performance by a large factor. Gets worse as your messages database increases.'),
128 128
     '#default_value' => variable_get('privatemsg_filter_searchbody', FALSE),
129
-  );
129
+    );
130 130
 
131 131
     $form['privatemsg_filter_tagfield_weight'] = array(
132 132
     '#type'          => 'textfield',
@@ -134,9 +134,9 @@  discard block
 block discarded – undo
134 134
     '#description'   => t('Use higher values to push the form lower down the page, lower or negative values to raise it higher.'),
135 135
     '#size'          => 4,
136 136
     '#default_value' => variable_get('privatemsg_filter_tagfield_weight', 10),
137
-  );
137
+    );
138 138
 
139
-  return system_settings_form($form);
139
+    return system_settings_form($form);
140 140
 }
141 141
 
142 142
 /**
@@ -145,26 +145,26 @@  discard block
 block discarded – undo
145 145
  * Add a filter widget to the message listing pages.
146 146
  */
147 147
 function privatemsg_filter_form_private_message_settings_alter(&$form, $form_state) {
148
-  $form['privatemsg_listing']['privatemsg_filter_default_list'] = array(
148
+    $form['privatemsg_listing']['privatemsg_filter_default_list'] = array(
149 149
     '#type' => 'radios',
150 150
     '#default_value' => variable_get('privatemsg_filter_default_list', 0),
151 151
     '#options' => array(t('Inbox'), t('All messages')),
152 152
     '#title' => t('Choose the default list option'),
153 153
     '#description' => t('Choose which of the two lists are shown by default when following the messages link.'),
154
-  );
155
-  // Add tags to the list of possible columns.
156
-  $form['privatemsg_listing']['privatemsg_display_fields']['#options']['tags'] = t('Tags');
154
+    );
155
+    // Add tags to the list of possible columns.
156
+    $form['privatemsg_listing']['privatemsg_display_fields']['#options']['tags'] = t('Tags');
157 157
 
158
-  $form['#submit'][] = 'privatemsg_filter_settings_submit';
158
+    $form['#submit'][] = 'privatemsg_filter_settings_submit';
159 159
 }
160 160
 
161 161
 /**
162 162
  * Rebuilding the menu if necessary.
163 163
  */
164 164
 function privatemsg_filter_settings_submit($form, &$form_state) {
165
-  if ($form['privatemsg_listing']['privatemsg_filter_default_list']['#default_value'] != $form_state['values']['privatemsg_filter_default_list']) {
165
+    if ($form['privatemsg_listing']['privatemsg_filter_default_list']['#default_value'] != $form_state['values']['privatemsg_filter_default_list']) {
166 166
     menu_rebuild();
167
-  }
167
+    }
168 168
 }
169 169
 
170 170
 /**
@@ -174,33 +174,33 @@  discard block
 block discarded – undo
174 174
  *   A single tag or an array of tags.
175 175
  */
176 176
 function privatemsg_filter_create_tags($tags) {
177
-  if (!is_array($tags)) {
177
+    if (!is_array($tags)) {
178 178
     $tags = array($tags);
179
-  }
179
+    }
180 180
 
181
-  $tag_ids = array();
181
+    $tag_ids = array();
182 182
 
183
-  foreach ($tags as $tag) {
183
+    foreach ($tags as $tag) {
184 184
     $tag = trim($tag);
185 185
     if (empty($tag)) {
186
-      // Do not save a blank tag.
187
-      continue;
186
+        // Do not save a blank tag.
187
+        continue;
188 188
     }
189 189
 
190 190
     // Check if the tag already exists and only create the tag if it does not.
191 191
     $tag_id = db_result(db_query("SELECT tag_id FROM {pm_tags} WHERE tag = '%s'", $tag));
192 192
     if (empty($tag_id) && privatemsg_user_access('create private message tags')) {
193
-      db_query("INSERT INTO {pm_tags} (tag) VALUES ('%s')", $tag);
194
-      $tag_id = db_last_insert_id('pm_tags', 'tag_id');
193
+        db_query("INSERT INTO {pm_tags} (tag) VALUES ('%s')", $tag);
194
+        $tag_id = db_last_insert_id('pm_tags', 'tag_id');
195 195
     }
196 196
     elseif (empty($tag_id)) {
197
-      // The user does not have permission to create new tags - disregard this tag and move onto the next.
198
-      drupal_set_message(t('Tag %tag was ignored because you do not have permission to create new tags.', array('%tag' => $tag)));
199
-      continue;
197
+        // The user does not have permission to create new tags - disregard this tag and move onto the next.
198
+        drupal_set_message(t('Tag %tag was ignored because you do not have permission to create new tags.', array('%tag' => $tag)));
199
+        continue;
200 200
     }
201 201
     $tag_ids[] = $tag_id;
202
-  }
203
-  return $tag_ids;
202
+    }
203
+    return $tag_ids;
204 204
 }
205 205
 
206 206
 /**
@@ -212,21 +212,21 @@  discard block
 block discarded – undo
212 212
  *   Id of the tag.
213 213
  */
214 214
 function privatemsg_filter_add_tags($threads, $tag_id, $account = NULL) {
215
-  if (!is_array($threads)) {
215
+    if (!is_array($threads)) {
216 216
     $threads = array($threads);
217
-  }
218
-  if (empty($account)) {
217
+    }
218
+    if (empty($account)) {
219 219
     global $user;
220 220
     $account = drupal_clone($user);
221
-  }
221
+    }
222 222
 
223
-  foreach ($threads as $thread) {
223
+    foreach ($threads as $thread) {
224 224
     // Make sure that we don't add a tag to a thread twice,
225 225
     // only insert if there is no such tag yet.
226 226
     if (db_result(db_query('SELECT COUNT(*) FROM {pm_tags_index} WHERE tag_id = %d AND (uid = %d AND thread_id = %d)', $tag_id, $account->uid, $thread)) == 0) {
227
-      db_query('INSERT INTO {pm_tags_index} (tag_id, uid, thread_id) VALUES (%d, %d, %d)', $tag_id, $account->uid, $thread);
227
+        db_query('INSERT INTO {pm_tags_index} (tag_id, uid, thread_id) VALUES (%d, %d, %d)', $tag_id, $account->uid, $thread);
228
+    }
228 229
     }
229
-  }
230 230
 }
231 231
 
232 232
 /**
@@ -238,238 +238,238 @@  discard block
 block discarded – undo
238 238
  *   Id of the tag - set to NULL to remove all tags.
239 239
  */
240 240
 function privatemsg_filter_remove_tags($threads, $tag_id = NULL, $account = NULL) {
241
-  if (!is_array($threads)) {
241
+    if (!is_array($threads)) {
242 242
     $threads = array($threads);
243
-  }
244
-  if (empty($account)) {
243
+    }
244
+    if (empty($account)) {
245 245
     global $user;
246 246
     $account = drupal_clone($user);
247
-  }
247
+    }
248 248
 
249
-  if (is_null($tag_id)) {
249
+    if (is_null($tag_id)) {
250 250
     // Delete all tag mapping.
251 251
     foreach ($threads as $thread) {
252
-      db_query('DELETE FROM {pm_tags_index} WHERE uid = %d AND thread_id = %d', $account->uid, $thread);
252
+        db_query('DELETE FROM {pm_tags_index} WHERE uid = %d AND thread_id = %d', $account->uid, $thread);
253
+    }
253 254
     }
254
-  }
255
-  else {
255
+    else {
256 256
     // Delete tag mapping for the specified tag.
257 257
     foreach ($threads as $thread) {
258
-      db_query('DELETE FROM {pm_tags_index} WHERE uid = %d AND thread_id = %d AND tag_id = %d', $account->uid, $thread, $tag_id);
258
+        db_query('DELETE FROM {pm_tags_index} WHERE uid = %d AND thread_id = %d AND tag_id = %d', $account->uid, $thread, $tag_id);
259
+    }
259 260
     }
260
-  }
261 261
 }
262 262
 
263 263
 function privatemsg_filter_get_filter($account) {
264
-  $filter = array();
265
-  if (isset($_GET['tags'])) {
264
+    $filter = array();
265
+    if (isset($_GET['tags'])) {
266 266
     $_GET['tags'] = urldecode($_GET['tags']);
267 267
     $tag_data = privatemsg_filter_get_tags_data($account);
268 268
     foreach (explode(',', $_GET['tags']) as $tag) {
269
-      if (isset($tag_data[$tag])) {
269
+        if (isset($tag_data[$tag])) {
270 270
         $filter['tags'][$tag] = $tag;
271
-      }
272
-      elseif (in_array($tag, $tag_data)) {
271
+        }
272
+        elseif (in_array($tag, $tag_data)) {
273 273
         $filter['tags'][array_search($tag, $tag_data)] = array_search($tag, $tag_data);
274
-      }
274
+        }
275
+    }
275 276
     }
276
-  }
277 277
 
278
-  if (isset($_GET['author'])) {
278
+    if (isset($_GET['author'])) {
279 279
     list($filter['author']) = _privatemsg_parse_userstring($_GET['author']);
280
-  }
280
+    }
281 281
 
282
-  if (isset($_GET['search'])) {
282
+    if (isset($_GET['search'])) {
283 283
     $filter['search'] = $_GET['search'];
284
-  }
284
+    }
285 285
 
286
-  if (!empty($filter)) {
286
+    if (!empty($filter)) {
287 287
     return $filter;
288
-  }
288
+    }
289 289
 
290
-  if (!empty($_SESSION['privatemsg_filter'])) {
290
+    if (!empty($_SESSION['privatemsg_filter'])) {
291 291
     return $_SESSION['privatemsg_filter'];
292
-  }
292
+    }
293 293
 
294 294
 }
295 295
 
296 296
 function privatemsg_filter_get_tags_data($account) {
297
-  static $tag_data;
297
+    static $tag_data;
298 298
 
299
-  if (is_array($tag_data)) {
299
+    if (is_array($tag_data)) {
300 300
     return $tag_data;
301
-  }
301
+    }
302 302
 
303
-  // Only show the tags that a user have used.
304
-  $query = _privatemsg_assemble_query(array('tags', 'privatemsg_filter'), $account);
305
-  $results = db_query($query['query']);
303
+    // Only show the tags that a user have used.
304
+    $query = _privatemsg_assemble_query(array('tags', 'privatemsg_filter'), $account);
305
+    $results = db_query($query['query']);
306 306
 
307
-  $tag_data = array();
308
-  while ($result = db_fetch_object($results)) {
307
+    $tag_data = array();
308
+    while ($result = db_fetch_object($results)) {
309 309
     $tag_data[$result->tag_id] = $result->tag;
310
-  }
311
-  return $tag_data;
310
+    }
311
+    return $tag_data;
312 312
 }
313 313
 
314 314
 function privatemsg_filter_dropdown(&$form_state, $account) {
315 315
 
316
-  drupal_add_css(drupal_get_path('module', 'privatemsg_filter') .'/privatemsg_filter.css');
316
+    drupal_add_css(drupal_get_path('module', 'privatemsg_filter') .'/privatemsg_filter.css');
317 317
 
318
-  $form['filter'] = array(
318
+    $form['filter'] = array(
319 319
     '#type' => 'fieldset',
320 320
     '#title' => t('Filter messages'),
321 321
     '#collapsible' => TRUE,
322 322
     '#collapsed' => TRUE,
323
-  );
324
-  $form['filter']['search'] = array(
323
+    );
324
+    $form['filter']['search'] = array(
325 325
     '#type' => 'textfield',
326 326
     '#title' => variable_get('privatemsg_filter_searchbody', FALSE) ? t('Search messages') : t('Search subjects'),
327 327
     '#weight' => -20
328
-  );
328
+    );
329 329
 
330
-  $form['filter']['author'] = array(
330
+    $form['filter']['author'] = array(
331 331
     '#type'               => 'textfield',
332 332
     '#title'              => t('Participants'),
333 333
     '#description'        => t('Separate multiple names with commas.'),
334 334
     '#weight'             => -5,
335 335
     '#size'               => 50,
336 336
     '#autocomplete_path'  => 'messages/filter/user-name-autocomplete',
337
-  );
337
+    );
338 338
 
339
-  // Only show form if the user has some messages tagged.
340
-  if (count($tag_data = privatemsg_filter_get_tags_data($account))) {
339
+    // Only show form if the user has some messages tagged.
340
+    if (count($tag_data = privatemsg_filter_get_tags_data($account))) {
341 341
     $form['filter']['tags'] = array(
342
-      '#type' => 'select',
343
-      '#title' => t('Tags'),
344
-      '#options' => $tag_data,
345
-      '#multiple' => TRUE,
346
-      '#size' => 5,
347
-      '#weight' => 0
348
-    );
349
-  }
342
+        '#type' => 'select',
343
+        '#title' => t('Tags'),
344
+        '#options' => $tag_data,
345
+        '#multiple' => TRUE,
346
+        '#size' => 5,
347
+        '#weight' => 0
348
+    );
349
+    }
350 350
     $form['filter']['submit'] = array(
351
-      '#type'     => 'submit',
352
-      '#value'    => t('Filter'),
353
-      '#prefix'   => '<div id="privatemsg-filter-buttons">',
354
-      '#weight'   => 10,
355
-      '#submit'   => array('privatemsg_filter_dropdown_submit'),
351
+        '#type'     => 'submit',
352
+        '#value'    => t('Filter'),
353
+        '#prefix'   => '<div id="privatemsg-filter-buttons">',
354
+        '#weight'   => 10,
355
+        '#submit'   => array('privatemsg_filter_dropdown_submit'),
356 356
     );
357 357
 
358 358
     $form['filter']['save'] = array(
359
-      '#type'     => 'submit',
360
-      '#value'    => t('Save filter'),
361
-      '#suffix'   => '</div>',
362
-      '#weight'   => 11,
363
-      '#submit'   => array('privatemsg_filter_dropdown_submit'),
359
+        '#type'     => 'submit',
360
+        '#value'    => t('Save filter'),
361
+        '#suffix'   => '</div>',
362
+        '#weight'   => 11,
363
+        '#submit'   => array('privatemsg_filter_dropdown_submit'),
364 364
     );
365 365
 
366 366
     if ($filter = privatemsg_filter_get_filter($account)) {
367
-      privatemsg_filter_dropdown_set_active($form, $filter);
367
+        privatemsg_filter_dropdown_set_active($form, $filter);
368 368
     }
369 369
 
370 370
     return $form;
371 371
 }
372 372
 
373 373
 function privatemsg_filter_dropdown_set_active(&$form, $filter) {
374
-  $form['filter']['#title'] = t('Filter messages (active)');
375
-  $form['filter']['#collapsed'] = FALSE;
374
+    $form['filter']['#title'] = t('Filter messages (active)');
375
+    $form['filter']['#collapsed'] = FALSE;
376 376
 
377
-  if (isset($filter['author'])) {
377
+    if (isset($filter['author'])) {
378 378
     $string = '';
379 379
     foreach ($filter['author'] as $author) {
380
-      $string .= $author->name . ', ';
380
+        $string .= $author->name . ', ';
381 381
     }
382 382
     $form['filter']['author']['#default_value'] = $string;
383
-  }
384
-  if (isset($filter['tags'])) {
383
+    }
384
+    if (isset($filter['tags'])) {
385 385
     $form['filter']['tags']['#default_value'] = $filter['tags'];
386
-  }
387
-  if (isset($filter['search'])) {
386
+    }
387
+    if (isset($filter['search'])) {
388 388
     $form['filter']['search']['#default_value'] = $filter['search'];
389
-  }
390
-
391
-  $form['filter']['reset'] = array(
392
-      '#type'     => 'submit',
393
-      '#value'    => t('Reset'),
394
-      '#suffix'   => '</div>',
395
-      '#weight'   => 12,
396
-      '#submit'   => array('privatemsg_filter_dropdown_submit'),
397
-  );
398
-  unset($form['filter']['save']['#suffix']);
389
+    }
390
+
391
+    $form['filter']['reset'] = array(
392
+        '#type'     => 'submit',
393
+        '#value'    => t('Reset'),
394
+        '#suffix'   => '</div>',
395
+        '#weight'   => 12,
396
+        '#submit'   => array('privatemsg_filter_dropdown_submit'),
397
+    );
398
+    unset($form['filter']['save']['#suffix']);
399 399
 }
400 400
 
401 401
 function privatemsg_filter_dropdown_submit($form, &$form_state) {
402 402
 
403
-  if (!empty($form_state['values']['author'])) {
403
+    if (!empty($form_state['values']['author'])) {
404 404
     list($form_state['values']['author']) = _privatemsg_parse_userstring($form_state['values']['author']);
405
-  }
405
+    }
406 406
 
407
-  switch ($form_state['values']['op']) {
407
+    switch ($form_state['values']['op']) {
408 408
     case t('Save filter'):
409 409
       $filter = array();
410
-      if (!empty($form_state['values']['tags'])) {
410
+        if (!empty($form_state['values']['tags'])) {
411 411
         $filter['tags'] = $form_state['values']['tags'];
412
-      }
413
-      if (!empty($form_state['values']['author'])) {
412
+        }
413
+        if (!empty($form_state['values']['author'])) {
414 414
         $filter['author'] = $form_state['values']['author'];
415
-      }
416
-      if (!empty($form_state['values']['search'])) {
415
+        }
416
+        if (!empty($form_state['values']['search'])) {
417 417
         $filter['search'] = $form_state['values']['search'];
418
-      }
419
-      $_SESSION['privatemsg_filter'] = $filter;
420
-      break;
418
+        }
419
+        $_SESSION['privatemsg_filter'] = $filter;
420
+        break;
421 421
     case t('Filter'):
422 422
       drupal_goto($_GET['q'], privatemsg_filter_create_get_query($form_state['values']));
423
-      return;
424
-      break;
423
+        return;
424
+        break;
425 425
     case t('Reset'):
426 426
       $_SESSION['privatemsg_filter'] = array();
427
-      break;
428
-  }
429
-  $form_state['redirect'] = $_GET['q'];
427
+        break;
428
+    }
429
+    $form_state['redirect'] = $_GET['q'];
430 430
 }
431 431
 
432 432
 function privatemsg_filter_create_get_query($filter) {
433
-  $query = array();
434
-  if (isset($filter['tags']) && !empty($filter['tags'])) {
433
+    $query = array();
434
+    if (isset($filter['tags']) && !empty($filter['tags'])) {
435 435
     $ids = array();
436 436
     foreach ($filter['tags'] as $tag) {
437
-      if ((int)$tag > 0) {
437
+        if ((int)$tag > 0) {
438 438
         $ids[] = $tag;
439
-      }
440
-      else {
439
+        }
440
+        else {
441 441
         $query['tags'][] = $tag;
442
-      }
442
+        }
443 443
     }
444 444
     $sql = 'SELECT pmt.tag FROM {pm_tags} pmt WHERE pmt.tag_id IN ('. implode(', ', $filter['tags']) .')';
445 445
     $result = db_query($sql);
446 446
     while ($row = db_fetch_object($result)) {
447
-      $query['tags'][] = $row->tag;
447
+        $query['tags'][] = $row->tag;
448 448
     }
449 449
 
450 450
     if (isset($query['tags'])) {
451
-      $query['tags'] = implode(',', $query['tags']);
451
+        $query['tags'] = implode(',', $query['tags']);
452
+    }
452 453
     }
453
-  }
454 454
 
455
-  if (isset($filter['author']) && !empty($filter['author'])) {
455
+    if (isset($filter['author']) && !empty($filter['author'])) {
456 456
     foreach ($filter['author'] as $author) {
457
-      if (is_object($author) && isset($author->uid) && isset($author->name)) {
457
+        if (is_object($author) && isset($author->uid) && isset($author->name)) {
458 458
         $query['author'][] = $author->name;
459
-      }
460
-      elseif ($author_obj = user_load($author)) {
459
+        }
460
+        elseif ($author_obj = user_load($author)) {
461 461
         $query['author'][] = $author_obj->name;
462
-      }
462
+        }
463 463
     }
464 464
     if (isset($query['author'])) {
465
-      $query['author'] = implode(',', $query['author']);
465
+        $query['author'] = implode(',', $query['author']);
466
+    }
466 467
     }
467
-  }
468 468
 
469
-  if (isset($filter['search']) && !empty($filter['search'])) {
469
+    if (isset($filter['search']) && !empty($filter['search'])) {
470 470
     $query['search'] = $filter['search'];
471
-  }
472
-  return $query;
471
+    }
472
+    return $query;
473 473
 }
474 474
 
475 475
 /**
@@ -478,14 +478,14 @@  discard block
 block discarded – undo
478 478
  * Adds a filter widget to the message listing pages.
479 479
  */
480 480
 function privatemsg_filter_form_privatemsg_list_alter(&$form, $form_state) {
481
-  global $user;
481
+    global $user;
482 482
 
483
-  if (privatemsg_user_access('filter private messages') && !empty($form['#data'])) {
483
+    if (privatemsg_user_access('filter private messages') && !empty($form['#data'])) {
484 484
     $form += privatemsg_filter_dropdown($form_state, $form['#account']);
485
-  }
485
+    }
486 486
 
487
-  $fields = array_filter(variable_get('privatemsg_display_fields', array('participants')));
488
-  if (in_array('tags', $fields)) {
487
+    $fields = array_filter(variable_get('privatemsg_display_fields', array('participants')));
488
+    if (in_array('tags', $fields)) {
489 489
     // Load thread id's of the current list.
490 490
     $threads = array_keys($form['#data']);
491 491
 
@@ -495,21 +495,21 @@  discard block
 block discarded – undo
495 495
     // Add them to #data
496 496
     $result = db_query($query['query']);
497 497
     while ($tag = db_fetch_array($result)) {
498
-      $form['#data'][$tag['thread_id']]['tags'][$tag['tag_id']] = $tag['tag'];
498
+        $form['#data'][$tag['thread_id']]['tags'][$tag['tag_id']] = $tag['tag'];
499
+    }
499 500
     }
500
-  }
501 501
 
502
-  $tags = privatemsg_filter_get_tags_data($user);
503
-  if (privatemsg_user_access('tag private messages') && !empty($tags) && !empty($form['#data'])) {
502
+    $tags = privatemsg_filter_get_tags_data($user);
503
+    if (privatemsg_user_access('tag private messages') && !empty($tags) && !empty($form['#data'])) {
504 504
     $options = array();
505 505
     $options[] = t('Apply tag...');
506 506
     foreach ($tags as $tag_id => $tag) {
507
-      $options[$tag_id] = $tag;
507
+        $options[$tag_id] = $tag;
508 508
     }
509 509
     $form['actions']['tag-add'] = array(
510
-      '#type'          => 'select',
511
-      '#options'       => $options,
512
-      '#default_value' => 0,
510
+        '#type'          => 'select',
511
+        '#options'       => $options,
512
+        '#default_value' => 0,
513 513
     );
514 514
     $form['actions']['tag-add-submit'] = array(
515 515
         '#prefix'     => '<div class="privatemsg-tag-add-submit">',
@@ -521,9 +521,9 @@  discard block
 block discarded – undo
521 521
     );
522 522
     $options[0] = t('Remove Tag...');
523 523
     $form['actions']['tag-remove'] = array(
524
-      '#type'          => 'select',
525
-      '#options'       => $options,
526
-      '#default_value' => 0,
524
+        '#type'          => 'select',
525
+        '#options'       => $options,
526
+        '#default_value' => 0,
527 527
     );
528 528
     $form['actions']['tag-remove-submit'] = array(
529 529
         '#prefix'     => '<div class="privatemsg-tag-remove-submit">',
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
 
537 537
     // JS for hiding the submit buttons.
538 538
     drupal_add_js(drupal_get_path('module', 'privatemsg_filter') .'/privatemsg-filter-list.js');
539
-  }
539
+    }
540 540
 }
541 541
 
542 542
 /**
@@ -545,12 +545,12 @@  discard block
 block discarded – undo
545 545
  * @see theme_privatemsg_list_header()
546 546
  */
547 547
 function phptemplate_privatemsg_list_header__tags() {
548
-   return array(
548
+    return array(
549 549
     'data' => t('Tags'),
550 550
     'key' => 'tags',
551 551
     'class' => 'privatemsg-header-tags',
552 552
     '#weight' => -42,
553
-  );
553
+    );
554 554
 }
555 555
 
556 556
 
@@ -560,48 +560,48 @@  discard block
 block discarded – undo
560 560
  * @see theme_privatemsg_list_field()
561 561
  */
562 562
 function phptemplate_privatemsg_list_field__tags($thread) {
563
-  if (!empty($thread['tags'])) {
563
+    if (!empty($thread['tags'])) {
564 564
     $tags = array();
565 565
 
566 566
     foreach ($thread['tags'] as $tag_id => $tag) {
567
-      $tags[] = l(strlen($tag) > 15 ? substr($tag, 0, 13) . '...' : $tag, 'messages', array(
567
+        $tags[] = l(strlen($tag) > 15 ? substr($tag, 0, 13) . '...' : $tag, 'messages', array(
568 568
         'attributes' => array('title' => $tag),
569 569
         'query' => array('tags' => $tag)
570
-      ));
570
+        ));
571 571
     }
572 572
     return array(
573
-      'data'  => implode(', ', $tags),
574
-      'class' => 'privatemsg-list-tags',
573
+        'data'  => implode(', ', $tags),
574
+        'class' => 'privatemsg-list-tags',
575 575
     );
576
-  }
576
+    }
577 577
 }
578 578
 
579 579
 /**
580 580
  * Form callback for adding a tag to threads.
581 581
  */
582 582
 function privatemsg_filter_add_tag_submit($form, &$form_state) {
583
-  $operation = array(
583
+    $operation = array(
584 584
     'callback' => 'privatemsg_filter_add_tags',
585 585
     'callback arguments' => array('tag_id' => $form_state['values']['tag-add']),
586 586
     'undo callback' => 'privatemsg_filter_remove_tags',
587 587
     'undo callback arguments' => array('tag_id' => $form_state['values']['tag-add']),
588
-  );
589
-  drupal_set_message(t('The selected conversations have been tagged.'));
590
-  privatemsg_operation_execute($operation, $form_state['values']['threads']);
588
+    );
589
+    drupal_set_message(t('The selected conversations have been tagged.'));
590
+    privatemsg_operation_execute($operation, $form_state['values']['threads']);
591 591
 }
592 592
 
593 593
 /**
594 594
  * Form callback for removing a tag to threads.
595 595
  */
596 596
 function privatemsg_filter_remove_tag_submit($form, &$form_state) {
597
-  $operation = array(
597
+    $operation = array(
598 598
     'callback' => 'privatemsg_filter_remove_tags',
599 599
     'callback arguments' => array('tag_id' => $form_state['values']['tag-remove']),
600 600
     'undo callback' => 'privatemsg_filter_add_tags',
601 601
     'undo callback arguments' => array('tag_id' => $form_state['values']['tag-remove']),
602
-  );
603
-  drupal_set_message(t('The tag has been removed from the selected conversations.'));
604
-  privatemsg_operation_execute($operation, $form_state['values']['threads']);
602
+    );
603
+    drupal_set_message(t('The tag has been removed from the selected conversations.'));
604
+    privatemsg_operation_execute($operation, $form_state['values']['threads']);
605 605
 }
606 606
 
607 607
 /**
@@ -609,114 +609,114 @@  discard block
 block discarded – undo
609 609
  */
610 610
 function privatemsg_filter_privatemsg_sql_list_alter(&$fragments, $account, $argument) {
611 611
 
612
-  // Check if its a filtered view.
613
-  if ($argument == 'sent') {
612
+    // Check if its a filtered view.
613
+    if ($argument == 'sent') {
614 614
     $fragments['where'][]       = "pm.author = %d";
615 615
     $fragments['query_args']['where'][]   = $account->uid;
616
-  }
617
-  if ($argument == 'inbox') {
616
+    }
617
+    if ($argument == 'inbox') {
618 618
     $fragments['having'][]       = '((SELECT pmf.author FROM {pm_message} pmf WHERE pmf.mid = pmi.thread_id) = %d AND COUNT(pmi.thread_id) > 1) OR (SELECT COUNT(*) FROM {pm_message} pmf INNER JOIN {pm_index} pmif ON (pmf.mid = pmif.mid) WHERE pmif.thread_id = pmi.thread_id AND pmf.author <> %d) > 0';
619 619
     $fragments['query_args']['having'][]   = $account->uid;
620 620
     $fragments['query_args']['having'][]   = $account->uid;
621
-  }
621
+    }
622 622
 
623
-  // Filter the message listing by any set tags.
624
-  if ($filter = privatemsg_filter_get_filter($account)) {
623
+    // Filter the message listing by any set tags.
624
+    if ($filter = privatemsg_filter_get_filter($account)) {
625 625
     $count = 0;
626 626
     if (isset($filter['tags']) && !empty($filter['tags'])) {
627
-      foreach ($filter['tags'] as $tag) {
627
+        foreach ($filter['tags'] as $tag) {
628 628
         $fragments['inner_join'][]  = "INNER JOIN {pm_tags_index} pmti$count ON (pmti$count.thread_id = pmi.thread_id AND pmti$count.uid = pmi.uid)";
629 629
         $fragments['where'][]       = "pmti$count.tag_id = %d";
630 630
         $fragments['query_args']['where'][]   = $tag;
631 631
         $count++;
632
-      }
632
+        }
633 633
     }
634 634
 
635 635
     if (isset($filter['author']) && !empty($filter['author'])) {
636
-      foreach ($filter['author'] as $author) {
636
+        foreach ($filter['author'] as $author) {
637 637
         $fragments['inner_join'][]  = "INNER JOIN {pm_index} pmi$count ON (pmi$count.mid = pm.mid)";
638 638
         $fragments['where'][]       = "pmi$count.uid = %d";
639 639
         $fragments['query_args']['where'][]   = $author->uid;
640 640
         $count++;
641
-      }
641
+        }
642 642
     }
643 643
 
644 644
     if (isset($filter['search']) && !empty($filter['search'])) {
645
-      if (variable_get('privatemsg_filter_searchbody', FALSE)) {
645
+        if (variable_get('privatemsg_filter_searchbody', FALSE)) {
646 646
         $fragments['where'][]       = "pm.subject LIKE '%s' OR pm.body LIKE '%s'";
647 647
         $fragments['query_args']['where'][]    = '%%'. $filter['search'] .'%%';
648 648
         $fragments['query_args']['where'][]    = '%%'. $filter['search'] .'%%';
649
-      }
650
-      else {
649
+        }
650
+        else {
651 651
         $fragments['where'][]       = "pm.subject LIKE '%s'";
652 652
         $fragments['query_args']['where'][]    = '%%'. $filter['search'] .'%%';
653
-      }
653
+        }
654
+    }
654 655
     }
655
-  }
656 656
 }
657 657
 
658 658
 /**
659 659
  * Hook into the view messages page to add a form for tagging purposes.
660 660
  */
661 661
 function privatemsg_filter_privatemsg_view_messages_alter(&$content, $thread) {
662
-  if (count($thread['messages']) > 0) {
662
+    if (count($thread['messages']) > 0) {
663 663
     $content['tags']['#value'] = drupal_get_form('privatemsg_filter_form');
664 664
     $content['tags']['#weight'] = variable_get('privatemsg_filter_tagfield_weight', 10);
665
-  }
665
+    }
666 666
 }
667 667
 
668 668
 /**
669 669
  * Form to show and allow modification of tagging information of a conversation.
670 670
  */
671 671
 function privatemsg_filter_form(&$form_state) {
672
-  global $user;
673
-  $thread_id = arg(2);
674
-
675
-  // Get a list of current tags for this thread
676
-  $query = _privatemsg_assemble_query(array('tags', 'privatemsg_filter'), $user, array($thread_id));
677
-  $results = db_query($query['query']);
678
-  $count = db_result(db_query($query['count']));
679
-  $tags = '';
680
-  while ($tag = db_fetch_array($results)) {
672
+    global $user;
673
+    $thread_id = arg(2);
674
+
675
+    // Get a list of current tags for this thread
676
+    $query = _privatemsg_assemble_query(array('tags', 'privatemsg_filter'), $user, array($thread_id));
677
+    $results = db_query($query['query']);
678
+    $count = db_result(db_query($query['count']));
679
+    $tags = '';
680
+    while ($tag = db_fetch_array($results)) {
681 681
     $tags .= $tag['tag'] . ', ';
682
-  }
682
+    }
683 683
 
684
-  $form['tags'] = array(
684
+    $form['tags'] = array(
685 685
     '#type' => 'fieldset',
686 686
     '#title' => t('Tags'),
687 687
     '#access' => privatemsg_user_access('tag private messages'),
688 688
     '#collapsible' => TRUE,
689 689
     '#collapsed' => empty($count) ? TRUE : FALSE,
690
-  );
691
-  $form['tags']['user_id'] = array(
690
+    );
691
+    $form['tags']['user_id'] = array(
692 692
     '#type' => 'value',
693 693
     '#value' => $user->uid,
694
-  );
695
-  $form['tags']['thread_id'] = array(
694
+    );
695
+    $form['tags']['thread_id'] = array(
696 696
     '#type' => 'value',
697 697
     '#value' => $thread_id,
698
-  );
698
+    );
699 699
 
700
-  $form['tags']['tags'] = array(
700
+    $form['tags']['tags'] = array(
701 701
     '#type'               => 'textfield',
702 702
     '#title'              => t('Tags for this conversation'),
703 703
     '#description'        => t('Separate multiple tags with commas.'),
704 704
     '#size'               => 50,
705 705
     '#default_value'      => $tags,
706 706
     '#autocomplete_path'  => 'messages/filter/tag-autocomplete',
707
-  );
707
+    );
708 708
 
709
-  $form['tags']['submit'] = array(
709
+    $form['tags']['submit'] = array(
710 710
     '#type'     => 'submit',
711 711
     '#value'    => t('Tag this conversation'),
712 712
     '#submit'   => array('privatemsg_filter_form_submit'),
713
-  );
713
+    );
714 714
 
715
-  return $form;
715
+    return $form;
716 716
 }
717 717
 
718 718
 function privatemsg_filter_form_submit($form, &$form_state) {
719
-  if (isset($form_state['values']['submit'])) {
719
+    if (isset($form_state['values']['submit'])) {
720 720
     $tags = explode(',', $form_state['values']['tags']);
721 721
 
722 722
     // Step 1 - Delete all tag mapping. I cannot think of a better way to remove tags that are no longer in the textfield, so ideas welcome.
@@ -727,10 +727,10 @@  discard block
 block discarded – undo
727 727
 
728 728
     // Step 3 - Save all the tagging data.
729 729
     foreach ($tag_ids as $tag_id) {
730
-      privatemsg_filter_add_tags($form_state['values']['thread_id'], $tag_id);
730
+        privatemsg_filter_add_tags($form_state['values']['thread_id'], $tag_id);
731 731
     }
732 732
     drupal_set_message(t('Tagging information has been saved.'));
733
-  }
733
+    }
734 734
 }
735 735
 
736 736
 /**
@@ -741,28 +741,28 @@  discard block
 block discarded – undo
741 741
  */
742 742
 function privatemsg_filter_tags_autocomplete($string) {
743 743
 
744
-  // 1: Parse $string and build a list of tags.
745
-  $tags = array();
746
-  $fragments = explode(',', $string);
747
-  foreach ($fragments as $index => $tag) {
744
+    // 1: Parse $string and build a list of tags.
745
+    $tags = array();
746
+    $fragments = explode(',', $string);
747
+    foreach ($fragments as $index => $tag) {
748 748
     $tag = trim($tag);
749 749
     $tags[$tag] = $tag;
750
-  }
750
+    }
751 751
 
752
-  // 2: Find the next tag suggestion.
753
-  $fragment = array_pop($tags);
754
-  $matches = array();
755
-  if (!empty($fragment)) {
752
+    // 2: Find the next tag suggestion.
753
+    $fragment = array_pop($tags);
754
+    $matches = array();
755
+    if (!empty($fragment)) {
756 756
     $query = _privatemsg_assemble_query(array('tags_autocomplete', 'privatemsg_filter'), $fragment, $tags);
757 757
     $result = db_query_range($query['query'], $fragment, 0, 10);
758 758
     $prefix = count($tags) ? implode(", ", $tags) .", " : '';
759 759
     // 3: Build proper suggestions and print.
760 760
     while ($tag = db_fetch_object($result)) {
761
-      $matches[$prefix . $tag->tag .", "] = $tag->tag;
761
+        $matches[$prefix . $tag->tag .", "] = $tag->tag;
762 762
     }
763
-  }
764
-  // convert to object to prevent drupal bug, see http://drupal.org/node/175361
765
-  drupal_json((object)$matches);
763
+    }
764
+    // convert to object to prevent drupal bug, see http://drupal.org/node/175361
765
+    drupal_json((object)$matches);
766 766
 }
767 767
 
768 768
 /**
@@ -781,19 +781,19 @@  discard block
 block discarded – undo
781 781
  *   Array of names that are already part of the autocomplete field.
782 782
  */
783 783
 function privatemsg_filter_privatemsg_sql_autocomplete_alter(&$fragments, $search, $names) {
784
-  global $user;
785
-  // arg(1) is an additional URL argument passed to the URL when only
786
-  // users that are listed as recipient for threads of that user should be
787
-  // displayed.
788
-  // @todo: Check if these results can be grouped to avoid unecessary loops.
789
-  if (arg(1) == 'filter') {
784
+    global $user;
785
+    // arg(1) is an additional URL argument passed to the URL when only
786
+    // users that are listed as recipient for threads of that user should be
787
+    // displayed.
788
+    // @todo: Check if these results can be grouped to avoid unecessary loops.
789
+    if (arg(1) == 'filter') {
790 790
     // JOIN on index entries where the to be selected user is a recipient.
791 791
     $fragments['inner_join'][] = 'INNER JOIN {pm_index} pip ON pip.uid = u.uid';
792 792
     // JOIN on rows where the current user is the recipient and that have the
793 793
     // same mid as those above.
794 794
     $fragments['inner_join'][] = 'INNER JOIN {pm_index} piu ON piu.uid = %d AND pip.mid = piu.mid';
795 795
     $fragments['query_args']['join'][] = $user->uid;
796
-  }
796
+    }
797 797
 }
798 798
 
799 799
 /**
@@ -809,19 +809,19 @@  discard block
 block discarded – undo
809 809
  *   Limit the number of tags *per thread*.
810 810
  */
811 811
 function privatemsg_filter_sql_tags(&$fragments, $user = NULL, $threads = NULL, $limit = NULL) {
812
-  $fragments['primary_table'] = '{pm_tags} t';
813
-  $fragments['select'][] = 't.tag';
814
-  $fragments['select'][] = 't.tag_id';
815
-  $fragments['select'][] = 't.public';
812
+    $fragments['primary_table'] = '{pm_tags} t';
813
+    $fragments['select'][] = 't.tag';
814
+    $fragments['select'][] = 't.tag_id';
815
+    $fragments['select'][] = 't.public';
816 816
 
817
-  if (!empty($threads)) {
817
+    if (!empty($threads)) {
818 818
     // If the tag list needs to be for specific threads.
819 819
     $fragments['select'][] = 'ti.thread_id';
820 820
     $fragments['inner_join'][]  = 'INNER JOIN {pm_tags_index} ti on ti.tag_id = t.tag_id';
821 821
     $fragments['where'][] = 'ti.thread_id IN (' . db_placeholders($threads) . ')';
822 822
     $fragments['query_args']['where'] += $threads;
823
-  }
824
-  else {
823
+    }
824
+    else {
825 825
     // Tag usage counter is only used when we select all tags.
826 826
     $fragments['select'][]      = 'COUNT(ti.thread_id) as count';
827 827
     // LEFT JOIN so that unused tags are displayed too.
@@ -829,33 +829,33 @@  discard block
 block discarded – undo
829 829
     $fragments['group_by'][]    = 't.tag_id';
830 830
     $fragments['group_by'][]    = 't.tag';
831 831
     $fragments['group_by'][]    = 't.public';
832
-  }
833
-  if (!empty($user)) {
832
+    }
833
+    if (!empty($user)) {
834 834
     $fragments['where'][]       = 'ti.uid = %d';
835 835
     $fragments['query_args']['where'][] = $user->uid;
836
-  }
837
-
838
-  // Only select n tags per thread (ordered per tag_id), see
839
-  // http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/.
840
-  //
841
-  // It does select how many tags for that thread/uid combination exist that
842
-  // have a lower tag_id and does only select those that have less than $limit.
843
-  //
844
-  // This should only have a very minor performance impact as most users won't
845
-  // tag a thread with 1000 different tags.
846
-  //
847
-  if ($limit) {
836
+    }
837
+
838
+    // Only select n tags per thread (ordered per tag_id), see
839
+    // http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/.
840
+    //
841
+    // It does select how many tags for that thread/uid combination exist that
842
+    // have a lower tag_id and does only select those that have less than $limit.
843
+    //
844
+    // This should only have a very minor performance impact as most users won't
845
+    // tag a thread with 1000 different tags.
846
+    //
847
+    if ($limit) {
848 848
     $fragments['where'][] = '(SELECT count(*) FROM {pm_tags_index} AS pmtic
849 849
                               WHERE pmtic.thread_id = ti.thread_id
850 850
                               AND pmtic.uid = ti.uid
851 851
                               AND pmtic.tag_id < ti.tag_id) < %d';
852 852
     $fragments['query_args']['where'][] = $limit;
853
-  }
854
-  elseif (!empty($threads) || !empty($user)) {
853
+    }
854
+    elseif (!empty($threads) || !empty($user)) {
855 855
     // Only add a sort when we are not loading the tags for the admin page.
856 856
     // Sorting is handled through tablesort_sql() then.
857 857
     $fragments['order_by'][] = 't.tag ASC';
858
-  }
858
+    }
859 859
 }
860 860
 
861 861
 /**
@@ -869,25 +869,25 @@  discard block
 block discarded – undo
869 869
  *   Array of tags not to be used as suggestions.
870 870
  */
871 871
 function privatemsg_filter_sql_tags_autocomplete(&$fragments, $search, $tags) {
872
-  global $user;
873
-
874
-  $fragments['primary_table'] = '{pm_tags} pmt';
875
-  $fragments['select'][] = 'pmt.tag';
876
-  $fragments['where'][] = "pmt.tag LIKE '%s'";
877
-  // Escape % to get through the placeholder replacement.
878
-  $fragments['query_args']['where'][] = $search .'%%';
879
-  if (!empty($tags)) {
872
+    global $user;
873
+
874
+    $fragments['primary_table'] = '{pm_tags} pmt';
875
+    $fragments['select'][] = 'pmt.tag';
876
+    $fragments['where'][] = "pmt.tag LIKE '%s'";
877
+    // Escape % to get through the placeholder replacement.
878
+    $fragments['query_args']['where'][] = $search .'%%';
879
+    if (!empty($tags)) {
880 880
     // Exclude tags.
881 881
     $fragments['where'][] = "pmt.tag NOT IN (". db_placeholders($tags, 'text') .")";
882 882
     $fragments['query_args']['where'] += $tags;
883
-  }
884
-  // LEFT JOIN to be able to load public, unused tags.
885
-  $fragments['inner_join'][]  = 'LEFT JOIN {pm_tags_index} pmti ON pmt.tag_id = pmti.tag_id AND pmti.uid = %d';
886
-  $fragments['query_args']['join'][] = $user->uid;
887
-  // Autocomplete should only display Tags used by that user or public tags.
888
-  // This is done to avoid information disclosure as part of tag names.
889
-  $fragments['where'][] = '(pmti.uid IS NOT NULL OR pmt.public = 1)';
890
-  $fragments['order_by'][] = 'pmt.tag ASC';
883
+    }
884
+    // LEFT JOIN to be able to load public, unused tags.
885
+    $fragments['inner_join'][]  = 'LEFT JOIN {pm_tags_index} pmti ON pmt.tag_id = pmti.tag_id AND pmti.uid = %d';
886
+    $fragments['query_args']['join'][] = $user->uid;
887
+    // Autocomplete should only display Tags used by that user or public tags.
888
+    // This is done to avoid information disclosure as part of tag names.
889
+    $fragments['where'][] = '(pmti.uid IS NOT NULL OR pmt.public = 1)';
890
+    $fragments['order_by'][] = 'pmt.tag ASC';
891 891
 }
892 892
 
893 893
 /**
@@ -898,10 +898,10 @@  discard block
 block discarded – undo
898 898
  * Implement hook_user().
899 899
  */
900 900
 function privatemsg_filter_user($op, &$edit, &$account, $category = NULL) {
901
-  switch ($op) {
902
-      case 'delete':
901
+    switch ($op) {
902
+        case 'delete':
903 903
       // Delete tag information of that user.
904 904
       db_query("DELETE FROM {pm_tags_index} WHERE uid = %d", $account->uid, $account->uid);
905
-      break;
906
-  }
905
+        break;
906
+    }
907 907
 }
Please login to merge, or discard this patch.
drupal/sites/default/boinc/modules/contrib/privatemsg/privatemsg.theme.inc 1 patch
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -75,11 +75,11 @@  discard block
 block discarded – undo
75 75
  * @see theme_privatemsg_list_field()
76 76
  */
77 77
 function phptemplate_privatemsg_list_field__participants($thread) {
78
-  $participants = _privatemsg_generate_user_array($thread['participants'], -4);
79
-  $field = array();
80
-  $field['data'] = _privatemsg_format_participants($participants, 3, TRUE);
81
-  $field['class'] = 'privatemsg-list-participants';
82
-  return $field;
78
+    $participants = _privatemsg_generate_user_array($thread['participants'], -4);
79
+    $field = array();
80
+    $field['data'] = _privatemsg_format_participants($participants, 3, TRUE);
81
+    $field['class'] = 'privatemsg-list-participants';
82
+    return $field;
83 83
 }
84 84
 
85 85
 /**
@@ -88,16 +88,16 @@  discard block
 block discarded – undo
88 88
  * @see theme_privatemsg_list_field()
89 89
  */
90 90
 function phptemplate_privatemsg_list_field__subject($thread) {
91
-  $field = array();
92
-  $options = array();
93
-  $is_new = '';
94
-  if (!empty($thread['is_new'])) {
91
+    $field = array();
92
+    $options = array();
93
+    $is_new = '';
94
+    if (!empty($thread['is_new'])) {
95 95
     $is_new = theme_mark(MARK_NEW);
96 96
     $options['fragment'] = 'new';
97
-  }
98
-  $field['data'] = l($thread['subject'], 'messages/view/' . $thread['thread_id'], $options) . $is_new;
99
-  $field['class'] = 'privatemsg-list-subject';
100
-  return $field;
97
+    }
98
+    $field['data'] = l($thread['subject'], 'messages/view/' . $thread['thread_id'], $options) . $is_new;
99
+    $field['class'] = 'privatemsg-list-subject';
100
+    return $field;
101 101
 }
102 102
 
103 103
 /**
@@ -106,15 +106,15 @@  discard block
 block discarded – undo
106 106
  * @see theme_privatemsg_list_field()
107 107
  */
108 108
 function phptemplate_privatemsg_list_field__count($thread) {
109
-  $field = array();
110
-  $field['data'] = $thread['count'];
111
-  $options = array();
112
-  if (!empty($thread['is_new']) && $thread['is_new'] < $thread['count']) {
109
+    $field = array();
110
+    $field['data'] = $thread['count'];
111
+    $options = array();
112
+    if (!empty($thread['is_new']) && $thread['is_new'] < $thread['count']) {
113 113
     $options['fragment'] = 'new';
114 114
     $field['data'] .= '<br />' . l((format_plural($thread['is_new'], '(1 new)', '(@count new)')), 'messages/view/' . $thread['thread_id'], $options);
115
-  }
116
-  $field['class'] = 'privatemsg-list-count';
117
-  return $field;
115
+    }
116
+    $field['class'] = 'privatemsg-list-count';
117
+    return $field;
118 118
 }
119 119
 
120 120
 /**
@@ -123,10 +123,10 @@  discard block
 block discarded – undo
123 123
  * @see theme_privatemsg_list_field()
124 124
  */
125 125
 function phptemplate_privatemsg_list_field__last_updated($thread) {
126
-  $field = array();
127
-  $field['data'] = format_date($thread['last_updated'], 'small');
128
-  $field['class'] = 'privatemsg-list-date';
129
-  return $field;
126
+    $field = array();
127
+    $field['data'] = format_date($thread['last_updated'], 'small');
128
+    $field['class'] = 'privatemsg-list-date';
129
+    return $field;
130 130
 }
131 131
 
132 132
 /**
@@ -135,10 +135,10 @@  discard block
 block discarded – undo
135 135
  * @see theme_privatemsg_list_field()
136 136
  */
137 137
 function phptemplate_privatemsg_list_field__thread_started($thread) {
138
-  $field = array();
139
-  $field['data'] = format_date($thread['thread_started'], 'small');
140
-  $field['class'] = 'privatemsg-list-date-started';
141
-  return $field;
138
+    $field = array();
139
+    $field['data'] = format_date($thread['thread_started'], 'small');
140
+    $field['class'] = 'privatemsg-list-date-started';
141
+    return $field;
142 142
 }
143 143
 
144 144
 /**
@@ -162,13 +162,13 @@  discard block
 block discarded – undo
162 162
  * @see theme_privatemsg_list_header()
163 163
  */
164 164
 function phptemplate_privatemsg_list_header__subject() {
165
-  return array(
165
+    return array(
166 166
     'data'    => t('Subject'),
167 167
     'field'   => 'subject',
168 168
     'key'     => 'subject',
169 169
     'class'   => 'privatemsg-header-subject',
170 170
     '#weight' => -40,
171
-  );
171
+    );
172 172
 }
173 173
 
174 174
 /**
@@ -177,12 +177,12 @@  discard block
 block discarded – undo
177 177
  * @see theme_privatemsg_list_header()
178 178
  */
179 179
 function phptemplate_privatemsg_list_header__count() {
180
-  return array(
180
+    return array(
181 181
     'data'    => t('Messages'),
182 182
     'key'     => 'count',
183 183
     'class'   => 'privatemsg-header-count',
184 184
     '#weight' => -25,
185
-  );
185
+    );
186 186
 }
187 187
 
188 188
 /**
@@ -191,12 +191,12 @@  discard block
 block discarded – undo
191 191
  * @see theme_privatemsg_list_header()
192 192
  */
193 193
 function phptemplate_privatemsg_list_header__participants() {
194
-  return array(
194
+    return array(
195 195
     'data'    => t('Participants'),
196 196
     'key'     => 'participants',
197 197
     'class'   => 'privatemsg-header-participants',
198 198
     '#weight' => -30,
199
-  );
199
+    );
200 200
 }
201 201
 
202 202
 /**
@@ -205,14 +205,14 @@  discard block
 block discarded – undo
205 205
  * @see theme_privatemsg_list_header()
206 206
  */
207 207
 function phptemplate_privatemsg_list_header__last_updated() {
208
-  return array(
208
+    return array(
209 209
     'data'    => t('Last Updated'),
210 210
     'field'   => 'last_updated',
211 211
     'key'     => 'last_updated',
212 212
     'sort'    => 'desc',
213 213
     'class'   => 'privatemsg-header-lastupdated',
214 214
     '#weight' => -20,
215
-  );
215
+    );
216 216
 }
217 217
 
218 218
 /**
@@ -221,13 +221,13 @@  discard block
 block discarded – undo
221 221
  * @see theme_privatemsg_list_header()
222 222
  */
223 223
 function phptemplate_privatemsg_list_header__thread_started() {
224
-  return array(
224
+    return array(
225 225
     'data'    => t('Started'),
226 226
     'field'   => 'thread_started',
227 227
     'key'     => 'thread_started',
228 228
     'class'   => 'privatemsg-header-threadstarted',
229 229
     '#weight' => -15,
230
-  );
230
+    );
231 231
 }
232 232
 
233 233
 /**
@@ -237,70 +237,70 @@  discard block
 block discarded – undo
237 237
  * by the header and field theme patterns.
238 238
  */
239 239
 function theme_privatemsg_list($form) {
240
-  $has_posts = !empty($form['#data']);
240
+    $has_posts = !empty($form['#data']);
241 241
 
242
-  drupal_add_css(drupal_get_path('module', 'privatemsg') .'/styles/privatemsg-list.css');
242
+    drupal_add_css(drupal_get_path('module', 'privatemsg') .'/styles/privatemsg-list.css');
243 243
 
244
-  // Load the table columns.
245
-  $columns = array_merge(array('subject', 'last_updated'), array_filter(variable_get('privatemsg_display_fields', array('participants'))));
244
+    // Load the table columns.
245
+    $columns = array_merge(array('subject', 'last_updated'), array_filter(variable_get('privatemsg_display_fields', array('participants'))));
246 246
 
247
-  // Load the themed list headers based on the available data.
248
-  $headers = _privatemsg_list_headers(!empty($form['#data']), $columns);
249
-  // sort the headers array based on the #weight property.
250
-  usort($headers, 'element_sort');
247
+    // Load the themed list headers based on the available data.
248
+    $headers = _privatemsg_list_headers(!empty($form['#data']), $columns);
249
+    // sort the headers array based on the #weight property.
250
+    usort($headers, 'element_sort');
251 251
 
252
-  $themed_rows = array();
253
-  // Check if there is atleast a single thread.
254
-  if ($has_posts) {
252
+    $themed_rows = array();
253
+    // Check if there is atleast a single thread.
254
+    if ($has_posts) {
255 255
     foreach ($form['#data'] as $thread_id => $data) {
256
-      // Theme the row.
257
-      $row = _privatemsg_list_thread($data);
258
-      $data = array();
259
-      // Render the checkbox.
260
-      $data[] = array('data' => drupal_render($form['threads'][$thread_id]), 'class' => 'privatemsg-list-select');
256
+        // Theme the row.
257
+        $row = _privatemsg_list_thread($data);
258
+        $data = array();
259
+        // Render the checkbox.
260
+        $data[] = array('data' => drupal_render($form['threads'][$thread_id]), 'class' => 'privatemsg-list-select');
261 261
 
262
-      // Store the #rows data in the same order as the header is, the key property of the header refers to the field that belongs to it.
263
-      foreach ($headers as $header) {
262
+        // Store the #rows data in the same order as the header is, the key property of the header refers to the field that belongs to it.
263
+        foreach ($headers as $header) {
264 264
         if (!empty($header['key'])) {
265
-          if (isset($row['data'][$header['key']])) {
265
+            if (isset($row['data'][$header['key']])) {
266 266
             $data[] = $row['data'][$header['key']];
267
-          }
268
-          else {
267
+            }
268
+            else {
269 269
             // Store a empty value so that the order is still correct.
270 270
             $data[] = '';
271
-          }
271
+            }
272
+        }
272 273
         }
273
-      }
274
-      // Replace the data
275
-      $row['data'] = $data;
276
-      $themed_rows[] = $row;
274
+        // Replace the data
275
+        $row['data'] = $data;
276
+        $themed_rows[] = $row;
277 277
     }
278
-  }
279
-  else {
278
+    }
279
+    else {
280 280
     // Display a message if now messages are available.
281 281
     $themed_rows[] = array(array('data' => t('No messages available.'), 'colspan' => count($headers)));
282
-  }
282
+    }
283 283
 
284
-  // Remove any data in header that we don't need anymore.
285
-  foreach ($headers as $id => $header) {
284
+    // Remove any data in header that we don't need anymore.
285
+    foreach ($headers as $id => $header) {
286 286
     unset($headers[$id]['key']);
287 287
     unset($headers[$id]['#weight']);
288
-  }
288
+    }
289 289
 
290
-  // Theme the table, pass all generated information to the table theme function.
291
-  $form['list'] = array('#value' => theme('table', $headers, $themed_rows, array('class' => 'privatemsg-list')), '#weight' => 5);
292
-  return drupal_render($form);
290
+    // Theme the table, pass all generated information to the table theme function.
291
+    $form['list'] = array('#value' => theme('table', $headers, $themed_rows, array('class' => 'privatemsg-list')), '#weight' => 5);
292
+    return drupal_render($form);
293 293
 }
294 294
 
295 295
 /**
296 296
  * Theme a block which displays the number of new messages a user has.
297 297
  */
298 298
 function theme_privatemsg_new_block($count) {
299
-  $text = format_plural($count, 'You have a new message, click here to read it',
299
+    $text = format_plural($count, 'You have a new message, click here to read it',
300 300
                         'You have @count new messages, click here to read them',
301 301
                         array('@count' => $count));
302 302
 
303
-  return l($text, 'messages', array('attributes' => array('id' => 'privatemsg-new-link')));
303
+    return l($text, 'messages', array('attributes' => array('id' => 'privatemsg-new-link')));
304 304
 }
305 305
 
306 306
 /**
Please login to merge, or discard this patch.
drupal/sites/default/boinc/modules/contrib/privatemsg/privatemsg.module 1 patch
Indentation   +1076 added lines, -1077 removed lines patch added patch discarded remove patch
@@ -22,13 +22,13 @@  discard block
 block discarded – undo
22 22
  * Implements hook_perm().
23 23
  */
24 24
 function privatemsg_perm() {
25
-  return array(
25
+    return array(
26 26
     'read privatemsg',
27 27
     'read all private messages',
28 28
     'administer privatemsg settings',
29 29
     'write privatemsg',
30 30
     'delete privatemsg',
31
-  );
31
+    );
32 32
 }
33 33
 
34 34
 /**
@@ -42,27 +42,27 @@  discard block
 block discarded – undo
42 42
  *   Array with user objects.
43 43
  */
44 44
 function _privatemsg_generate_user_array($userstring, $slice = NULL) {
45
-  static $user_cache = array();
46
-
47
-  // Convert user uid list (uid1,uid2,uid3) into an array. If $slice is not NULL
48
-  // pass that as argument to array_slice(). For example, -4 will only load the
49
-  // last four users.
50
-  // This is done to avoid loading user objects that are not displayed, for
51
-  // obvious performance reasons.
52
-  $users = explode(',', $userstring);
53
-  if (!is_null($slice)) {
45
+    static $user_cache = array();
46
+
47
+    // Convert user uid list (uid1,uid2,uid3) into an array. If $slice is not NULL
48
+    // pass that as argument to array_slice(). For example, -4 will only load the
49
+    // last four users.
50
+    // This is done to avoid loading user objects that are not displayed, for
51
+    // obvious performance reasons.
52
+    $users = explode(',', $userstring);
53
+    if (!is_null($slice)) {
54 54
     $users = array_slice($users, $slice);
55
-  }
56
-  $participants = array();
57
-  foreach ($users as $uid) {
55
+    }
56
+    $participants = array();
57
+    foreach ($users as $uid) {
58 58
     if (!array_key_exists($uid, $user_cache)) {
59
-      $user_cache[$uid] = user_load($uid);
59
+        $user_cache[$uid] = user_load($uid);
60 60
     }
61 61
     if (is_object($user_cache[$uid])) {
62
-      $participants[$uid] = $user_cache[$uid];
62
+        $participants[$uid] = $user_cache[$uid];
63
+    }
63 64
     }
64
-  }
65
-  return $participants;
65
+    return $participants;
66 66
 }
67 67
 
68 68
 /**
@@ -80,60 +80,60 @@  discard block
 block discarded – undo
80 80
  *   String with formated user objects, like user1, user2.
81 81
  */
82 82
 function _privatemsg_format_participants($part_array, $limit = NULL, $no_text = FALSE) {
83
-  if (count($part_array) > 0) {
83
+    if (count($part_array) > 0) {
84 84
     $to = array();
85 85
     $limited = FALSE;
86 86
     foreach ($part_array as $account) {
87
-      if (is_int($limit) && count($to) >= $limit) {
87
+        if (is_int($limit) && count($to) >= $limit) {
88 88
         $limited = TRUE;
89 89
         break;
90
-      }
91
-      $to[] = theme('username', $account);
90
+        }
91
+        $to[] = theme('username', $account);
92 92
     }
93 93
 
94 94
     $limit_string = '';
95 95
     if ($limited) {
96
-      $limit_string = t(' and others');
96
+        $limit_string = t(' and others');
97 97
     }
98 98
 
99 99
 
100 100
     if ($no_text) {
101
-      return implode(', ', $to) . $limit_string;
101
+        return implode(', ', $to) . $limit_string;
102 102
     }
103 103
 
104 104
     $last = array_pop($to);
105 105
     if (count($to) == 0) { // Only one participant
106
-      return t("From !last", array('!last' => $last));
106
+        return t("From !last", array('!last' => $last));
107 107
     }
108 108
     else { // Multipe participants..
109
-      $participants = implode(', ', $to);
110
-      return t('Participants: !participants and !last', array('!participants' => $participants, '!last' => $last));
109
+        $participants = implode(', ', $to);
110
+        return t('Participants: !participants and !last', array('!participants' => $participants, '!last' => $last));
111
+    }
111 112
     }
112
-  }
113
-  return '';
113
+    return '';
114 114
 }
115 115
 
116 116
 /**
117 117
  * Implements hook_menu().
118 118
  */
119 119
 function privatemsg_menu() {
120
-  $items['messages'] = array(
120
+    $items['messages'] = array(
121 121
     'title'            => 'Messages',
122 122
     'title callback'  => 'privatemsg_title_callback',
123 123
     'page callback'    => 'drupal_get_form',
124 124
     'page arguments'   => array('privatemsg_list', 'list'),
125 125
     'access callback'  => 'privatemsg_user_access',
126 126
     'type'             => MENU_NORMAL_ITEM,
127
-  );
128
-  $items['messages/list'] = array(
127
+    );
128
+    $items['messages/list'] = array(
129 129
     'title'            => 'Messages',
130 130
     'page callback'    => 'drupal_get_form',
131 131
     'page arguments'   => array('privatemsg_list', 'list'),
132 132
     'access callback'  => 'privatemsg_user_access',
133 133
     'type'             => MENU_DEFAULT_LOCAL_TASK,
134 134
     'weight'           => -10,
135
-  );
136
-  $items['messages/view/%privatemsg_thread'] = array(
135
+    );
136
+    $items['messages/view/%privatemsg_thread'] = array(
137 137
     'title'            => 'Read message',
138 138
     // Set the third argument to TRUE so that we can show access denied instead
139 139
     // of not found.
@@ -144,16 +144,16 @@  discard block
 block discarded – undo
144 144
     'access arguments' => array(2),
145 145
     'type'             => MENU_LOCAL_TASK,
146 146
     'weight'           => -5,
147
-  );
148
-  $items['messages/delete/%privatemsg_thread/%privatemsg_message'] = array(
147
+    );
148
+    $items['messages/delete/%privatemsg_thread/%privatemsg_message'] = array(
149 149
     'title'            => 'Delete message',
150 150
     'page callback'    => 'drupal_get_form',
151 151
     'page arguments'   => array('privatemsg_delete', 2, 3),
152 152
     'access callback'  => 'privatemsg_user_access',
153 153
     'access arguments' => array('delete privatemsg'),
154 154
     'type'             => MENU_CALLBACK,
155
-  );
156
-  $items['messages/new'] = array(
155
+    );
156
+    $items['messages/new'] = array(
157 157
     'title'            => 'Write new message',
158 158
     'page callback'    => 'drupal_get_form',
159 159
     'page arguments'   => array('privatemsg_new', 2, 3, NULL),
@@ -161,24 +161,24 @@  discard block
 block discarded – undo
161 161
     'access arguments' => array('write privatemsg'),
162 162
     'type'             => MENU_LOCAL_TASK,
163 163
     'weight'           => -3,
164
-  );
165
-  // Auto-completes available user names & removes duplicates.
166
-  $items['messages/user-name-autocomplete'] = array(
164
+    );
165
+    // Auto-completes available user names & removes duplicates.
166
+    $items['messages/user-name-autocomplete'] = array(
167 167
     'page callback'    => 'privatemsg_user_name_autocomplete',
168 168
     'access callback'  => 'privatemsg_user_access',
169 169
     'access arguments' => array('write privatemsg'),
170 170
     'type'             => MENU_CALLBACK,
171 171
     'weight'           => -10,
172
-  );
173
-  $items['admin/settings/messages'] = array(
172
+    );
173
+    $items['admin/settings/messages'] = array(
174 174
     'title'            => 'Private messages',
175 175
     'description'      => 'Configure private messaging settings.',
176 176
     'page callback'    => 'drupal_get_form',
177 177
     'page arguments'   => array('private_message_settings'),
178 178
     'access arguments' => array('administer privatemsg settings'),
179 179
     'type'             => MENU_NORMAL_ITEM,
180
-  );
181
-  $items['admin/settings/messages/default'] = array(
180
+    );
181
+    $items['admin/settings/messages/default'] = array(
182 182
     'title'            => 'Private messages',
183 183
     'description'      => 'Configure private messaging settings.',
184 184
     'page callback'    => 'drupal_get_form',
@@ -186,24 +186,24 @@  discard block
 block discarded – undo
186 186
     'access arguments' => array('administer privatemsg settings'),
187 187
     'type'             => MENU_DEFAULT_LOCAL_TASK,
188 188
     'weight'           => -10,
189
-  );
190
-  $items['messages/undo/action'] = array(
189
+    );
190
+    $items['messages/undo/action'] = array(
191 191
     'title'            => 'Private messages',
192 192
     'description'      => 'Undo last thread action',
193 193
     'page callback'    => 'privatemsg_undo_action',
194 194
     'access arguments' => array('read privatemsg'),
195 195
     'type'             => MENU_CALLBACK,
196
-  );
197
-  $items['user/%/messages'] = array(
196
+    );
197
+    $items['user/%/messages'] = array(
198 198
     'title' => 'Messages',
199 199
     'page callback'    => 'drupal_get_form',
200 200
     'page arguments'   => array('privatemsg_list', 'list', 1),
201 201
     'access callback'  => 'privatemsg_user_access',
202 202
     'access arguments' => array('read all private messages'),
203 203
     'type' => MENU_LOCAL_TASK,
204
-  );
204
+    );
205 205
 
206
-  return $items;
206
+    return $items;
207 207
 }
208 208
 
209 209
 /**
@@ -220,17 +220,17 @@  discard block
 block discarded – undo
220 220
  * @ingroup api
221 221
  */
222 222
 function privatemsg_user_access($permission = 'read privatemsg', $account = NULL) {
223
-  if ( $account === NULL ) {
223
+    if ( $account === NULL ) {
224 224
     global $user;
225 225
     $account = $user;
226
-  }
227
-  if (!$account->uid) { // Disallow anonymous access, regardless of permissions
226
+    }
227
+    if (!$account->uid) { // Disallow anonymous access, regardless of permissions
228 228
     return FALSE;
229
-  }
230
-  if (!user_access($permission, $account)) {
229
+    }
230
+    if (!user_access($permission, $account)) {
231 231
     return FALSE;
232
-  }
233
-  return TRUE;
232
+    }
233
+    return TRUE;
234 234
 }
235 235
 
236 236
 /**
@@ -247,15 +247,15 @@  discard block
 block discarded – undo
247 247
  * @ingroup api
248 248
  */
249 249
 function privatemsg_view_access($thread = array()) {
250
-  // Do not allow access to threads without messages.
251
-  if (empty($thread['messages'])) {
250
+    // Do not allow access to threads without messages.
251
+    if (empty($thread['messages'])) {
252 252
     // Count all messages, if there
253 253
     return FALSE;
254
-  }
255
-  if (privatemsg_user_access('read privatemsg') && arg(1) == 'view') {
254
+    }
255
+    if (privatemsg_user_access('read privatemsg') && arg(1) == 'view') {
256 256
     return TRUE;
257
-  }
258
-  return FALSE;
257
+    }
258
+    return FALSE;
259 259
 }
260 260
 
261 261
 /**
@@ -284,142 +284,141 @@  discard block
 block discarded – undo
284 284
  *
285 285
  *   If no messages are found, or the thread_id is invalid, the function returns
286 286
  *   FALSE.
287
-
288 287
  * @ingroup api
289 288
  */
290 289
 function privatemsg_thread_load($thread_id, $account = NULL, $start = NULL, $useAccessDenied = FALSE) {
291
-  static $threads = array();
292
-  if ((int)$thread_id > 0) {
290
+    static $threads = array();
291
+    if ((int)$thread_id > 0) {
293 292
     $thread = array('thread_id' => $thread_id);
294 293
 
295 294
     if (is_null($account)) {
296
-      global $user;
297
-      $account = drupal_clone($user);
295
+        global $user;
296
+        $account = drupal_clone($user);
298 297
     }
299 298
 
300 299
     if (!isset($threads[$account->uid])) {
301
-      $threads[$account->uid] = array();
300
+        $threads[$account->uid] = array();
302 301
     }
303 302
 
304 303
     if (!array_key_exists($thread_id, $threads[$account->uid])) {
305
-      // Load the list of participants.
306
-      $query = _privatemsg_assemble_query('participants', $thread_id);
307
-      $participants = db_query($query['query']);
308
-      $thread['participants'] = array();
309
-      while ($participant = db_fetch_object($participants)) {
304
+        // Load the list of participants.
305
+        $query = _privatemsg_assemble_query('participants', $thread_id);
306
+        $participants = db_query($query['query']);
307
+        $thread['participants'] = array();
308
+        while ($participant = db_fetch_object($participants)) {
310 309
         $thread['participants'][$participant->uid] = $participant;
311
-      }
312
-      $thread['read_all'] = FALSE;
313
-      if (!array_key_exists($account->uid, $thread['participants']) && privatemsg_user_access('read all private messages', $account)) {
310
+        }
311
+        $thread['read_all'] = FALSE;
312
+        if (!array_key_exists($account->uid, $thread['participants']) && privatemsg_user_access('read all private messages', $account)) {
314 313
         $thread['read_all'] = TRUE;
315
-      }
314
+        }
316 315
 
317
-      // Load messages returned by the messages query with privatemsg_message_load_multiple().
318
-      $query = _privatemsg_assemble_query('messages', array($thread_id), $thread['read_all'] ? NULL : $account);
319
-      $thread['message_count'] = $thread['to'] = db_result(db_query($query['count']));
320
-      $thread['from'] = 1;
321
-      // Check if we need to limit the messages.
322
-      $max_amount = variable_get('privatemsg_view_max_amount', 20);
316
+        // Load messages returned by the messages query with privatemsg_message_load_multiple().
317
+        $query = _privatemsg_assemble_query('messages', array($thread_id), $thread['read_all'] ? NULL : $account);
318
+        $thread['message_count'] = $thread['to'] = db_result(db_query($query['count']));
319
+        $thread['from'] = 1;
320
+        // Check if we need to limit the messages.
321
+        $max_amount = variable_get('privatemsg_view_max_amount', 20);
323 322
 
324
-      // If there is no start value, select based on get params.
325
-      if (is_null($start)) {
323
+        // If there is no start value, select based on get params.
324
+        if (is_null($start)) {
326 325
         if (isset($_GET['start']) && $_GET['start'] < $thread['message_count']) {
327
-          $start = $_GET['start'];
326
+            $start = $_GET['start'];
328 327
         }
329 328
         elseif (!variable_get('privatemsg_view_use_max_as_default', FALSE) && $max_amount == PRIVATEMSG_UNLIMITED) {
330
-          $start = PRIVATEMSG_UNLIMITED;
329
+            $start = PRIVATEMSG_UNLIMITED;
331 330
         }
332 331
         else {
333
-          $start = $thread['message_count'] - (variable_get('privatemsg_view_use_max_as_default', FALSE) ? variable_get('privatemsg_view_default_amount', 10) : $max_amount);
332
+            $start = $thread['message_count'] - (variable_get('privatemsg_view_use_max_as_default', FALSE) ? variable_get('privatemsg_view_default_amount', 10) : $max_amount);
333
+        }
334 334
         }
335
-      }
336 335
 
337
-      if ($start != PRIVATEMSG_UNLIMITED) {
336
+        if ($start != PRIVATEMSG_UNLIMITED) {
338 337
         if ($max_amount == PRIVATEMSG_UNLIMITED) {
339
-          $last_page = 0;
340
-          $max_amount = $thread['message_count'];
338
+            $last_page = 0;
339
+            $max_amount = $thread['message_count'];
341 340
         }
342 341
         else {
343
-          // Calculate the number of messages on the "last" page to avoid
344
-          // message overlap.
345
-          // Note - the last page lists the earliest messages, not the latest.
346
-          $paging_count = variable_get('privatemsg_view_use_max_as_default', FALSE) ? $thread['message_count'] - variable_get('privatemsg_view_default_amount', 10) : $thread['message_count'];
347
-          $last_page = $paging_count % $max_amount;
342
+            // Calculate the number of messages on the "last" page to avoid
343
+            // message overlap.
344
+            // Note - the last page lists the earliest messages, not the latest.
345
+            $paging_count = variable_get('privatemsg_view_use_max_as_default', FALSE) ? $thread['message_count'] - variable_get('privatemsg_view_default_amount', 10) : $thread['message_count'];
346
+            $last_page = $paging_count % $max_amount;
348 347
         }
349 348
 
350 349
         // Sanity check - we cannot start from a negative number.
351 350
         if ($start < 0) {
352
-          $start = 0;
351
+            $start = 0;
353 352
         }
354 353
         $thread['start'] = $start;
355 354
 
356 355
         //If there are newer messages on the page, show pager link allowing to go to the newer messages.
357 356
         if (($start + $max_amount + 1) < $thread['message_count']) {
358
-          $thread['to'] = $start + $max_amount;
359
-          $thread['newer_start'] = $start + $max_amount;
357
+            $thread['to'] = $start + $max_amount;
358
+            $thread['newer_start'] = $start + $max_amount;
360 359
         }
361 360
         if ($start - $max_amount >= 0) {
362
-          $thread['older_start'] = $start - $max_amount;
361
+            $thread['older_start'] = $start - $max_amount;
363 362
         }
364 363
         elseif ($start > 0) {
365
-          $thread['older_start'] = 0;
364
+            $thread['older_start'] = 0;
366 365
         }
367 366
 
368 367
         // Do not show messages on the last page that would show on the page
369 368
         // before. This will only work when using the visual pager.
370 369
         if ($start < $last_page && $max_amount != PRIVATEMSG_UNLIMITED && $max_amount < $thread['message_count']) {
371
-          unset($thread['older_start']);
372
-          $thread['to'] = $thread['newer_start'] = $max_amount = $last_page;
373
-          // Start from the first message - this is a specific hack to make sure
374
-          // the message display has sane paging on the last page.
375
-          $start = 0;
370
+            unset($thread['older_start']);
371
+            $thread['to'] = $thread['newer_start'] = $max_amount = $last_page;
372
+            // Start from the first message - this is a specific hack to make sure
373
+            // the message display has sane paging on the last page.
374
+            $start = 0;
376 375
         }
377 376
         // Visual counts start from 1 instead of zero, so plus one.
378 377
         $thread['from'] = $start + 1;
379 378
         $conversation = db_query_range($query['query'], $start, $max_amount);
380
-      }
381
-      else {
379
+        }
380
+        else {
382 381
         $conversation = db_query($query['query']);
383
-      }
384
-      $mids = array();
385
-      while ($result = db_fetch_array($conversation)) {
382
+        }
383
+        $mids = array();
384
+        while ($result = db_fetch_array($conversation)) {
386 385
         $mids[] = $result['mid'];
387
-      }
388
-      // Load messages returned by the messages query.
389
-      $thread['messages'] = privatemsg_message_load_multiple($mids, $thread['read_all'] ? NULL : $account);
386
+        }
387
+        // Load messages returned by the messages query.
388
+        $thread['messages'] = privatemsg_message_load_multiple($mids, $thread['read_all'] ? NULL : $account);
390 389
 
391
-      // If there are no messages, don't allow access to the thread.
392
-      if (empty($thread['messages'])) {
390
+        // If there are no messages, don't allow access to the thread.
391
+        if (empty($thread['messages'])) {
393 392
         if ($useAccessDenied) {
394
-          // Generate new query with read all to see if the thread does exist.
395
-          $query = _privatemsg_assemble_query('messages', array($thread_id), NULL);
396
-          $exists = db_result(db_query($query['count']));
397
-          if (!$exists) {
393
+            // Generate new query with read all to see if the thread does exist.
394
+            $query = _privatemsg_assemble_query('messages', array($thread_id), NULL);
395
+            $exists = db_result(db_query($query['count']));
396
+            if (!$exists) {
398 397
             // Thread does not exist, display 404.
399 398
             $thread = FALSE;
400
-          }
399
+            }
401 400
         }
402 401
         else {
403
-          $thread = FALSE;
402
+            $thread = FALSE;
403
+        }
404 404
         }
405
-      }
406
-      else {
405
+        else {
407 406
         // General data, assume subject is the same for all messages of that thread.
408 407
         $thread['user'] = $account;
409 408
         $message = current($thread['messages']);
410 409
         $thread['subject'] = $message['subject'];
411
-      }
412
-      $threads[$account->uid][$thread_id] = $thread;
410
+        }
411
+        $threads[$account->uid][$thread_id] = $thread;
413 412
     }
414 413
 
415 414
     return $threads[$account->uid][$thread_id];
416
-  }
417
-  return FALSE;
415
+    }
416
+    return FALSE;
418 417
 }
419 418
 
420 419
 function private_message_view_options() {
421
-  $options = module_invoke_all('privatemsg_view_template');
422
-  return $options;
420
+    $options = module_invoke_all('privatemsg_view_template');
421
+    return $options;
423 422
 }
424 423
 
425 424
 /**
@@ -435,108 +434,108 @@  discard block
 block discarded – undo
435 434
  * };
436 435
  */
437 436
 function privatemsg_privatemsg_view_template() {
438
-  return array(
437
+    return array(
439 438
     'privatemsg-view' => 'Default view',
440
-  );
439
+    );
441 440
 }
442 441
 
443 442
 function private_message_settings() {
444
-  $form = array();
443
+    $form = array();
445 444
 
446
-  $form['theming_settings'] = array(
445
+    $form['theming_settings'] = array(
447 446
     '#type'        => 'fieldset',
448 447
     '#collapsible' => TRUE,
449 448
     '#collapsed'   => TRUE,
450 449
     '#title'       => t('Theming settings'),
451
-  );
452
-  $form['theming_settings']['private_message_view_template'] = array(
450
+    );
451
+    $form['theming_settings']['private_message_view_template'] = array(
453 452
     '#type'          => 'radios',
454 453
     '#title'         => t('Private message display template'),
455 454
     '#default_value' => variable_get('private_message_view_template', 'privatemsg-view'),
456 455
     '#options'       => private_message_view_options(),
457
-  );
458
-  $form['privatemsg_display_loginmessage'] = array(
456
+    );
457
+    $form['privatemsg_display_loginmessage'] = array(
459 458
     '#type' => 'checkbox',
460 459
     '#title' => t('Inform the user about new messages on login'),
461 460
     '#default_value' => variable_get('privatemsg_display_loginmessage', TRUE),
462 461
     '#description' => t('This option can safely be disabled if the "New message indication" block is used instead.'),
463
-  );
462
+    );
464 463
 
465
-  $form['flush_deleted'] = array(
464
+    $form['flush_deleted'] = array(
466 465
     '#type'        => 'fieldset',
467 466
     '#collapsible' => TRUE,
468 467
     '#collapsed'   => TRUE,
469 468
     '#title'       => t('Flush deleted messages'),
470 469
     '#description' => t('By default, deleted messages are only hidden from the user but still stored in the database. These settings control if and when messages should be removed.'),
471
-  );
470
+    );
472 471
 
473
-  $form['flush_deleted']['privatemsg_flush_enabled'] = array(
472
+    $form['flush_deleted']['privatemsg_flush_enabled'] = array(
474 473
     '#type'          => 'checkbox',
475 474
     '#title'         => t('Flush deleted messages'),
476 475
     '#default_value' => variable_get('privatemsg_flush_enabled', FALSE),
477 476
     '#description'   => t('Enable the flushing of deleted messages. Requires that cron is enabled'),
478
-  );
477
+    );
479 478
 
480
-  $form['flush_deleted']['privatemsg_flush_days'] = array(
479
+    $form['flush_deleted']['privatemsg_flush_days'] = array(
481 480
     '#type' => 'select',
482 481
     '#title' => t('Flush messages after they have been deleted for more days than'),
483 482
     '#default_value' => variable_get('privatemsg_flush_days', 30),
484 483
     '#options' => drupal_map_assoc(array(0, 1, 2, 5, 10, 30, 100)),
485
-  );
484
+    );
486 485
 
487
-  $form['flush_deleted']['privatemsg_flush_max'] = array(
486
+    $form['flush_deleted']['privatemsg_flush_max'] = array(
488 487
     '#type' => 'select',
489 488
     '#title' => t('Maximum number of messages to flush per cron run'),
490 489
     '#default_value' => variable_get('privatemsg_flush_max', 200),
491 490
     '#options' => drupal_map_assoc(array(50, 100, 200, 500, 1000)),
492
-  );
491
+    );
493 492
 
494
-  $form['privatemsg_listing'] = array(
493
+    $form['privatemsg_listing'] = array(
495 494
     '#type' => 'fieldset',
496 495
     '#title' => t('Configure listings'),
497 496
     '#collapsible' => TRUE,
498 497
     '#collapsed' => FALSE,
499
-  );
498
+    );
500 499
 
501
-  $form['privatemsg_listing']['privatemsg_per_page'] = array(
500
+    $form['privatemsg_listing']['privatemsg_per_page'] = array(
502 501
     '#type' => 'select',
503 502
     '#title' => t('Threads per page'),
504 503
     '#default_value' => variable_get('privatemsg_per_page', 25),
505 504
     '#options' => drupal_map_assoc(array(10, 25, 50, 75, 100)),
506 505
     '#description' => t('Choose the number of conversations that should be listed per page.'),
507
-  );
506
+    );
508 507
 
509
-  $form['privatemsg_listing']['privatemsg_display_fields'] = array(
508
+    $form['privatemsg_listing']['privatemsg_display_fields'] = array(
510 509
     '#type' => 'checkboxes',
511 510
     '#title' => t('Configure fields'),
512 511
     '#description' => t('Select which columns/fields should be displayed in the message listings. Subject and Last updated cannot be disabled.'),
513 512
     '#options' => array(
514
-      'participants'    => t('Participants'),
515
-      'thread_started'  => t('Started'),
516
-      'count'           => t('Messages'),
513
+        'participants'    => t('Participants'),
514
+        'thread_started'  => t('Started'),
515
+        'count'           => t('Messages'),
517 516
     ),
518 517
     '#default_value' => variable_get('privatemsg_display_fields', array('participants')),
519
-  );
518
+    );
520 519
 
521
-  $amounts = drupal_map_assoc(array(5, 10, 20, 30, 50, 70, 90, 150, 200, 250, 300));
522
-  $form['privatemsg_listing']['privatemsg_view_max_amount'] = array(
520
+    $amounts = drupal_map_assoc(array(5, 10, 20, 30, 50, 70, 90, 150, 200, 250, 300));
521
+    $form['privatemsg_listing']['privatemsg_view_max_amount'] = array(
523 522
     '#type'          => 'select',
524 523
     '#title'         => t('Number of messages on thread pages'),
525 524
     '#options'       => $amounts + array(PRIVATEMSG_UNLIMITED => t('Unlimited')),
526 525
     '#default_value' => variable_get('privatemsg_view_max_amount', 20),
527 526
     '#description'   => t('Threads will not show more than this number of messages on a single page.'),
528 527
     '#weight'        => 10,
529
-  );
528
+    );
530 529
 
531
-  $form['privatemsg_listing']['privatemsg_view_use_max_as_default'] = array(
530
+    $form['privatemsg_listing']['privatemsg_view_use_max_as_default'] = array(
532 531
     '#type'          => 'checkbox',
533 532
     '#title'         => t('Display different amount of messages on first thread page'),
534 533
     '#default_value' => variable_get('privatemsg_view_use_max_as_default', FALSE),
535 534
     '#description'   => t('By default, the first thread page shows the maximally allowed amount of messages. Enable this checkbox to set a different value.'),
536 535
     '#weight'        => 15,
537
-  );
536
+    );
538 537
 
539
-  $form['privatemsg_listing']['privatemsg_view_default_amount'] = array(
538
+    $form['privatemsg_listing']['privatemsg_view_default_amount'] = array(
540 539
     '#prefix'        => '<div id="privatemsg-view-default-button">',
541 540
     '#suffix'        => '</div>',
542 541
     '#type'          => 'select',
@@ -545,15 +544,15 @@  discard block
 block discarded – undo
545 544
     '#description'   => t('The number of messages to be displayed on first thread page. Displays the newest messages.'),
546 545
     '#options'       => $amounts,
547 546
     '#weight'        => 20,
548
-  );
549
-  drupal_add_js(drupal_get_path('module', 'privatemsg') .'/privatemsg-admin.js');
547
+    );
548
+    drupal_add_js(drupal_get_path('module', 'privatemsg') .'/privatemsg-admin.js');
550 549
 
551
-  $form['#submit'][] = 'private_message_settings_submit';
552
-  return system_settings_form($form);
550
+    $form['#submit'][] = 'private_message_settings_submit';
551
+    return system_settings_form($form);
553 552
 }
554 553
 
555 554
 function private_message_settings_submit() {
556
-  drupal_rebuild_theme_registry();
555
+    drupal_rebuild_theme_registry();
557 556
 }
558 557
 
559 558
 /**
@@ -563,107 +562,107 @@  discard block
 block discarded – undo
563 562
  * old enough are flushed.
564 563
  */
565 564
 function privatemsg_cron() {
566
-  if (variable_get('privatemsg_flush_enabled', FALSE)) {
565
+    if (variable_get('privatemsg_flush_enabled', FALSE)) {
567 566
     $query = _privatemsg_assemble_query('deleted', variable_get('privatemsg_flush_days', 30));
568 567
     $result = db_query($query['query']);
569 568
 
570 569
     $flushed = 0;
571 570
     while (($row = db_fetch_array($result)) && ($flushed < variable_get('privatemsg_flush_max', 200))) {
572
-      $message = privatemsg_message_load($row['mid']);
573
-      module_invoke_all('privatemsg_message_flush', $message);
571
+        $message = privatemsg_message_load($row['mid']);
572
+        module_invoke_all('privatemsg_message_flush', $message);
574 573
 
575
-      // Delete recipients of the message.
576
-      db_query('DELETE FROM {pm_index} WHERE mid = %d', $row['mid']);
577
-      // Delete message itself.
578
-      db_query('DELETE FROM {pm_message} WHERE mid = %d', $row['mid']);
579
-      $flushed++;
574
+        // Delete recipients of the message.
575
+        db_query('DELETE FROM {pm_index} WHERE mid = %d', $row['mid']);
576
+        // Delete message itself.
577
+        db_query('DELETE FROM {pm_message} WHERE mid = %d', $row['mid']);
578
+        $flushed++;
579
+    }
580 580
     }
581
-  }
582 581
 }
583 582
 
584 583
 function privatemsg_theme() {
585
-  return array(
584
+    return array(
586 585
     'privatemsg_view'    => array(
587
-      'arguments'        => array('message' => NULL),
588
-      'template'         => variable_get('private_message_view_template', 'privatemsg-view'), // 'privatemsg',
586
+        'arguments'        => array('message' => NULL),
587
+        'template'         => variable_get('private_message_view_template', 'privatemsg-view'), // 'privatemsg',
589 588
     ),
590 589
     'privatemsg_from'    => array(
591
-      'arguments'        => array('author' => NULL),
592
-      'template'         => 'privatemsg-from',
590
+        'arguments'        => array('author' => NULL),
591
+        'template'         => 'privatemsg-from',
593 592
     ),
594 593
     'privatemsg_recipients' => array(
595
-      'arguments'        => array('message' => NULL),
596
-      'template'         => 'privatemsg-recipients',
594
+        'arguments'        => array('message' => NULL),
595
+        'template'         => 'privatemsg-recipients',
597 596
     ),
598 597
     'privatemsg_between' => array(
599
-      'arguments'        => array('recipients' => NULL),
600
-      'template'         => 'privatemsg-between',
598
+        'arguments'        => array('recipients' => NULL),
599
+        'template'         => 'privatemsg-between',
601 600
     ),
602 601
     'privatemsg_list'    => array(
603
-      'file'                  => 'privatemsg.theme.inc',
604
-      'path'                  => drupal_get_path('module', 'privatemsg'),
605
-      'arguments'        => array('form'),
602
+        'file'                  => 'privatemsg.theme.inc',
603
+        'path'                  => drupal_get_path('module', 'privatemsg'),
604
+        'arguments'        => array('form'),
606 605
     ),
607 606
     // Define pattern for header/field templates. The theme system will register all
608 607
     // theme functions that start with the defined pattern.
609 608
     'privatemsg_list_header'  => array(
610
-      'file'                  => 'privatemsg.theme.inc',
611
-      'path'                  => drupal_get_path('module', 'privatemsg'),
612
-      'pattern'               => 'privatemsg_list_header__',
613
-      'arguments'             => array(),
609
+        'file'                  => 'privatemsg.theme.inc',
610
+        'path'                  => drupal_get_path('module', 'privatemsg'),
611
+        'pattern'               => 'privatemsg_list_header__',
612
+        'arguments'             => array(),
614 613
     ),
615 614
     'privatemsg_list_field'   => array(
616
-      'file'                  => 'privatemsg.theme.inc',
617
-      'path'                  => drupal_get_path('module', 'privatemsg'),
618
-      'pattern'               => 'privatemsg_list_field__',
619
-      'arguments'             => array('thread'),
615
+        'file'                  => 'privatemsg.theme.inc',
616
+        'path'                  => drupal_get_path('module', 'privatemsg'),
617
+        'pattern'               => 'privatemsg_list_field__',
618
+        'arguments'             => array('thread'),
620 619
     ),
621 620
     'privatemsg_new_block'  => array(
622
-      'file'                  => 'privatemsg.theme.inc',
623
-      'path'                  => drupal_get_path('module', 'privatemsg'),
624
-      'arguments'             => array('count'),
621
+        'file'                  => 'privatemsg.theme.inc',
622
+        'path'                  => drupal_get_path('module', 'privatemsg'),
623
+        'arguments'             => array('count'),
625 624
     ),
626
-  );
625
+    );
627 626
 }
628 627
 
629 628
 function template_preprocess_privatemsg_view(&$vars) {
630 629
 //  drupal_set_message('<pre>'. print_r($vars,1 ) . '</pre>');
631 630
 
632
-  $message = $vars['message'];
633
-  $vars['mid'] = isset($message['mid']) ? $message['mid'] : NULL;
634
-  $vars['thread_id'] = isset($message['thread_id']) ? $message['thread_id'] : NULL;
635
-  $vars['author_picture'] = theme('user_picture', $message['author']);
636
-  $vars['author_name_link'] = theme('username', $message['author']);
637
-  /**
638
-   * @todo perhaps make this timestamp configurable via admin UI?
639
-   */
640
-  $vars['message_timestamp'] = format_date($message['timestamp'], 'small');
641
-  $vars['message_body'] = check_markup($message['body'], $message['format'], FALSE);
642
-  if (isset($vars['mid']) && isset($vars['thread_id']) && privatemsg_user_access('delete privatemsg')) {
631
+    $message = $vars['message'];
632
+    $vars['mid'] = isset($message['mid']) ? $message['mid'] : NULL;
633
+    $vars['thread_id'] = isset($message['thread_id']) ? $message['thread_id'] : NULL;
634
+    $vars['author_picture'] = theme('user_picture', $message['author']);
635
+    $vars['author_name_link'] = theme('username', $message['author']);
636
+    /**
637
+     * @todo perhaps make this timestamp configurable via admin UI?
638
+     */
639
+    $vars['message_timestamp'] = format_date($message['timestamp'], 'small');
640
+    $vars['message_body'] = check_markup($message['body'], $message['format'], FALSE);
641
+    if (isset($vars['mid']) && isset($vars['thread_id']) && privatemsg_user_access('delete privatemsg')) {
643 642
     $vars['message_actions'][] = array('title' => t('Delete message'), 'href' => 'messages/delete/' . $vars['thread_id'] . '/' . $vars['mid']);
644
-  }
645
-  $vars['message_anchors'][] = 'privatemsg-mid-' . $vars['mid'];
646
-  if (!empty($message['is_new'])) {
643
+    }
644
+    $vars['message_anchors'][] = 'privatemsg-mid-' . $vars['mid'];
645
+    if (!empty($message['is_new'])) {
647 646
     $vars['message_anchors'][] = 'new';
648 647
     $vars['new'] = drupal_ucfirst(t('new'));
649
-  }
648
+    }
650 649
 
651
-  // call hook_privatemsg_message_view_alter
652
-  drupal_alter('privatemsg_message_view', $vars);
650
+    // call hook_privatemsg_message_view_alter
651
+    drupal_alter('privatemsg_message_view', $vars);
653 652
 
654
-  $vars['message_actions'] = !empty($vars['message_actions']) ? theme('links', $vars['message_actions'], array('class' => 'message-actions')) : '';
653
+    $vars['message_actions'] = !empty($vars['message_actions']) ? theme('links', $vars['message_actions'], array('class' => 'message-actions')) : '';
655 654
 
656
-  $vars['anchors'] = '';
657
-  foreach ($vars['message_anchors'] as $anchor) {
655
+    $vars['anchors'] = '';
656
+    foreach ($vars['message_anchors'] as $anchor) {
658 657
     $vars['anchors'] .= '<a name="' . $anchor . '"></a>';
659
-  }
658
+    }
660 659
 }
661 660
 
662 661
 function template_preprocess_privatemsg_recipients(&$vars) {
663
-  $vars['participants'] = ''; // assign a default empty value
664
-  if (isset($vars['message']['participants'])) {
662
+    $vars['participants'] = ''; // assign a default empty value
663
+    if (isset($vars['message']['participants'])) {
665 664
     $vars['participants'] = _privatemsg_format_participants($vars['message']['participants']);
666
-  }
665
+    }
667 666
 }
668 667
 
669 668
 /**
@@ -680,49 +679,49 @@  discard block
 block discarded – undo
680 679
  *   Form array
681 680
  */
682 681
 function privatemsg_list(&$form_state, $argument = 'list', $uid = NULL) {
683
-  global $user;
682
+    global $user;
684 683
 
685
-  // Setting default behavior...
686
-  $account = $user;
687
-  // Because uid is submitted by the menu system, it's a string not a integer.
688
-  if ((int)$uid > 0 && $uid != $user->uid) {
684
+    // Setting default behavior...
685
+    $account = $user;
686
+    // Because uid is submitted by the menu system, it's a string not a integer.
687
+    if ((int)$uid > 0 && $uid != $user->uid) {
689 688
     // Trying to view someone else's messages...
690 689
     if (!privatemsg_user_access('read all private messages')) {
691
-      drupal_set_message(t("You do not have sufficient rights to view someone else's messages"), 'warning');
690
+        drupal_set_message(t("You do not have sufficient rights to view someone else's messages"), 'warning');
692 691
     }
693 692
     elseif ($account_check = user_load(array('uid' => $uid))) {
694
-      // Has rights and user_load return an array so user does exist
695
-      $account = $account_check;
693
+        // Has rights and user_load return an array so user does exist
694
+        $account = $account_check;
695
+    }
696 696
     }
697
-  }
698
-  // By this point we have figured out for which user we are listing messages and now it is safe to use $account->uid in the listing query.
697
+    // By this point we have figured out for which user we are listing messages and now it is safe to use $account->uid in the listing query.
699 698
 
700
-  $query = _privatemsg_assemble_query('list', $account, $argument);
701
-  $result = pager_query($query['query'], variable_get('privatemsg_per_page', 25), 0, $query['count']);
699
+    $query = _privatemsg_assemble_query('list', $account, $argument);
700
+    $result = pager_query($query['query'], variable_get('privatemsg_per_page', 25), 0, $query['count']);
702 701
 
703
-  $threads = array();
704
-  $form['#data'] = array();
705
-  while ($row = db_fetch_array($result)) {
702
+    $threads = array();
703
+    $form['#data'] = array();
704
+    while ($row = db_fetch_array($result)) {
706 705
     // Store the raw row data.
707 706
     $form['#data'][$row['thread_id']] = $row;
708 707
     // store thread id for the checkboxes array
709 708
     $threads[$row['thread_id']] = '';
710
-  }
711
-  if (!empty($form['#data'])) {
709
+    }
710
+    if (!empty($form['#data'])) {
712 711
     $form['actions'] = _privatemsg_action_form();
713
-  }
712
+    }
714 713
 
715
-  // Save the currently active account, used for actions.
716
-  $form['account'] = array('#type' => 'value', '#value' => $account);
714
+    // Save the currently active account, used for actions.
715
+    $form['account'] = array('#type' => 'value', '#value' => $account);
717 716
 
718
-  // Define checkboxes, pager and theme
719
-  $form['threads'] = array('#type' => 'checkboxes', '#options' => $threads);
720
-  $form['pager'] = array('#value' => theme('pager'), '#weight' => 20);
721
-  $form['#theme'] = 'privatemsg_list';
717
+    // Define checkboxes, pager and theme
718
+    $form['threads'] = array('#type' => 'checkboxes', '#options' => $threads);
719
+    $form['pager'] = array('#value' => theme('pager'), '#weight' => 20);
720
+    $form['#theme'] = 'privatemsg_list';
722 721
 
723
-  // Store the account for which the threads are displayed.
724
-  $form['#account'] = $account;
725
-  return $form;
722
+    // Store the account for which the threads are displayed.
723
+    $form['#account'] = $account;
724
+    return $form;
726 725
 }
727 726
 
728 727
 /**
@@ -736,12 +735,12 @@  discard block
 block discarded – undo
736 735
  *   User object, defaults to the current user
737 736
  */
738 737
 function privatemsg_message_change_status($pmid, $status, $account = NULL) {
739
-  if (!$account) {
738
+    if (!$account) {
740 739
     global $user;
741 740
     $account = $user;
742
-  }
743
-  $query = "UPDATE {pm_index} SET is_new = %d WHERE mid = %d AND uid = %d";
744
-  db_query($query, $status, $pmid, $account->uid);
741
+    }
742
+    $query = "UPDATE {pm_index} SET is_new = %d WHERE mid = %d AND uid = %d";
743
+    db_query($query, $status, $pmid, $account->uid);
745 744
 }
746 745
 
747 746
 /**
@@ -753,16 +752,16 @@  discard block
 block discarded – undo
753 752
  * @ingroup api
754 753
  */
755 754
 function privatemsg_unread_count($account = NULL) {
756
-  static $counts = array();
757
-  if (!$account || $account->uid == 0) {
755
+    static $counts = array();
756
+    if (!$account || $account->uid == 0) {
758 757
     global $user;
759 758
     $account = $user;
760
-  }
761
-  if ( !isset($counts[$account->uid])) {
759
+    }
760
+    if ( !isset($counts[$account->uid])) {
762 761
     $query = _privatemsg_assemble_query('unread_count', $account);
763 762
     $counts[$account->uid] = db_result(db_query($query['query']));
764
-  }
765
-  return $counts[$account->uid];
763
+    }
764
+    return $counts[$account->uid];
766 765
 }
767 766
 
768 767
 /**
@@ -776,282 +775,282 @@  discard block
 block discarded – undo
776 775
  * @see privatemsg_thread_load()
777 776
  */
778 777
 function privatemsg_view($thread) {
779
-  drupal_set_title(check_plain($thread['subject']));
778
+    drupal_set_title(check_plain($thread['subject']));
780 779
 
781
-  // Generate paging links.
782
-  $older = '';
783
-  if (isset($thread['older_start'])) {
780
+    // Generate paging links.
781
+    $older = '';
782
+    if (isset($thread['older_start'])) {
784 783
     $options = array(
785
-      'query' => array('start' => $thread['older_start']),
786
-      'title' => t('Display older messages'),
784
+        'query' => array('start' => $thread['older_start']),
785
+        'title' => t('Display older messages'),
787 786
     );
788
-     $older = l(t('<<'), 'messages/view/' . $thread['thread_id'], $options);
789
-  }
790
-  $newer = '';
791
-  if (isset($thread['newer_start'])) {
787
+        $older = l(t('<<'), 'messages/view/' . $thread['thread_id'], $options);
788
+    }
789
+    $newer = '';
790
+    if (isset($thread['newer_start'])) {
792 791
     $options = array(
793
-      'query' => array('start' => $thread['newer_start']),
794
-      'title' => t('Display newer messages'),
792
+        'query' => array('start' => $thread['newer_start']),
793
+        'title' => t('Display newer messages'),
795 794
     );
796 795
     $newer = l(t('>>'), 'messages/view/' . $thread['thread_id'], $options);
797
-  }
798
-  $substitutions = array('@from' => $thread['from'], '@to' => $thread['to'], '@total' => $thread['message_count'], '!previous_link' => $older, '!newer_link' => $newer);
799
-  $title = t('!previous_link Displaying messages @from - @to of @total !newer_link', $substitutions);
800
-  $content['pager_top'] = array(
796
+    }
797
+    $substitutions = array('@from' => $thread['from'], '@to' => $thread['to'], '@total' => $thread['message_count'], '!previous_link' => $older, '!newer_link' => $newer);
798
+    $title = t('!previous_link Displaying messages @from - @to of @total !newer_link', $substitutions);
799
+    $content['pager_top'] = array(
801 800
     '#value'  => trim($title),
802 801
     '#prefix' => '<div class="privatemsg-view-pager">',
803 802
     '#suffix' => '</div>',
804 803
     '#weight' => -10,
805
-  );
804
+    );
806 805
 
807
-  // Display a copy at the end.
808
-  $content['pager_bottom'] = $content['pager_top'];
809
-  $content['pager_bottom']['#weight'] = 3;
806
+    // Display a copy at the end.
807
+    $content['pager_bottom'] = $content['pager_top'];
808
+    $content['pager_bottom']['#weight'] = 3;
810 809
 
811
-  // Render the participants.
812
-  $content['participants']['#value'] = theme('privatemsg_recipients', $thread);
813
-  $content['participants']['#weight'] = -5;
810
+    // Render the participants.
811
+    $content['participants']['#value'] = theme('privatemsg_recipients', $thread);
812
+    $content['participants']['#weight'] = -5;
814 813
 
815
-  // Render the messages.
816
-  $output = '';
817
-  foreach ($thread['messages'] as $pmid => $message) {
814
+    // Render the messages.
815
+    $output = '';
816
+    foreach ($thread['messages'] as $pmid => $message) {
818 817
     // Set message as read and theme it.
819 818
     if (!empty($message['is_new'])) {
820
-      privatemsg_message_change_status($pmid, PRIVATEMSG_READ, $thread['user']);
819
+        privatemsg_message_change_status($pmid, PRIVATEMSG_READ, $thread['user']);
821 820
     }
822 821
     $output .= theme('privatemsg_view', $message);
823
-  }
824
-  $content['messages']['#value'] = $output;
825
-  $content['messages']['#weight'] = 0;
822
+    }
823
+    $content['messages']['#value'] = $output;
824
+    $content['messages']['#weight'] = 0;
826 825
 
827
-  // Display the reply form if user is allowed to use it.
828
-  if (privatemsg_user_access('write privatemsg')) {
826
+    // Display the reply form if user is allowed to use it.
827
+    if (privatemsg_user_access('write privatemsg')) {
829 828
     $content['reply']['#value'] = drupal_get_form('privatemsg_new', $thread['participants'], $thread['subject'], $thread['thread_id'], $thread['read_all']);
830 829
     $content['reply']['#weight'] = 5;
831
-  }
830
+    }
832 831
 
833
-  // Check after calling the privatemsg_new form so that this message is only
834
-  // displayed when we are not sending a message.
835
-  if ($thread['read_all']) {
832
+    // Check after calling the privatemsg_new form so that this message is only
833
+    // displayed when we are not sending a message.
834
+    if ($thread['read_all']) {
836 835
     // User has permission to read all messages AND is not a participant of the current thread.
837 836
     drupal_set_message(t('This conversation is being viewed with escalated priviledges and may not be the same as shown to normal users.'), 'warning');
838
-  }
837
+    }
839 838
 
840
-  // Allow other modules to hook into the $content array and alter it.
841
-  drupal_alter('privatemsg_view_messages', $content, $thread);
842
-  return drupal_render($content);
839
+    // Allow other modules to hook into the $content array and alter it.
840
+    drupal_alter('privatemsg_view_messages', $content, $thread);
841
+    return drupal_render($content);
843 842
 }
844 843
 
845 844
 
846 845
 function privatemsg_new(&$form_state, $recipients = array(), $subject = '', $thread_id = NULL, $read_all = FALSE) {
847
-  global $user;
846
+    global $user;
848 847
 
849
-  $recipients_string = '';
850
-  $body      = '';
848
+    $recipients_string = '';
849
+    $body      = '';
851 850
 
852
-  // convert recipients to array of user objects
853
-  if (!empty($recipients) && is_string($recipients) || is_int($recipients)) {
851
+    // convert recipients to array of user objects
852
+    if (!empty($recipients) && is_string($recipients) || is_int($recipients)) {
854 853
     $recipients = _privatemsg_generate_user_array($recipients);
855
-  }
856
-  elseif (is_object($recipients)) {
854
+    }
855
+    elseif (is_object($recipients)) {
857 856
     $recipients = array($recipients);
858
-  }
859
-  elseif (empty($recipients) && is_string($recipients)) {
857
+    }
858
+    elseif (empty($recipients) && is_string($recipients)) {
860 859
     $recipients = array();
861
-  }
860
+    }
862 861
 
863
-  $usercount = 0;
864
-  $to = array();
865
-  $to_themed = array();
866
-  $blocked = FALSE;
867
-  foreach ($recipients as $recipient) {
862
+    $usercount = 0;
863
+    $to = array();
864
+    $to_themed = array();
865
+    $blocked = FALSE;
866
+    foreach ($recipients as $recipient) {
868 867
     if (in_array($recipient->name, $to)) {
869
-      // We already added the recipient to the list, skip him.
870
-      continue;
868
+        // We already added the recipient to the list, skip him.
869
+        continue;
871 870
     }
872 871
     // Check if another module is blocking the sending of messages to the recipient by current user.
873 872
     $user_blocked = module_invoke_all('privatemsg_block_message', $user, array($recipient->uid => $recipient));
874 873
     if (!count($user_blocked) <> 0 && $recipient->uid) {
875
-      if ($recipient->uid == $user->uid) {
874
+        if ($recipient->uid == $user->uid) {
876 875
         $usercount++;
877 876
         // Skip putting author in the recipients list for now.
878 877
         continue;
879
-      }
880
-      $to[] = $recipient->name;
881
-      $to_themed[$recipient->uid] = theme('username', $recipient);
878
+        }
879
+        $to[] = $recipient->name;
880
+        $to_themed[$recipient->uid] = theme('username', $recipient);
882 881
     }
883 882
     else {
884
-      // Recipient list contains blocked users.
885
-      $blocked = TRUE;
883
+        // Recipient list contains blocked users.
884
+        $blocked = TRUE;
885
+    }
886 886
     }
887
-  }
888 887
 
889
-  if (empty($to) && $usercount >= 1 && !$blocked) {
888
+    if (empty($to) && $usercount >= 1 && !$blocked) {
890 889
     // Assume the user sent message to own account as if the usercount is one or less, then the user sent a message but not to self.
891 890
     $to[] = $user->name;
892 891
     $to_themed[$user->uid] = theme('username', $user);
893
-  }
892
+    }
894 893
 
895
-  if (!empty($to)) {
894
+    if (!empty($to)) {
896 895
     $recipients_string = implode(', ', $to);
897
-  }
898
-  if (isset($form_state['values'])) {
896
+    }
897
+    if (isset($form_state['values'])) {
899 898
     if (isset($form_state['values']['recipient'])) {
900
-      $recipients_string = $form_state['values']['recipient'];
899
+        $recipients_string = $form_state['values']['recipient'];
901 900
 
902 901
     }
903 902
     $subject   = $form_state['values']['subject'];
904 903
     $body      = $form_state['values']['body'];
905
-  }
906
-  if (!$thread_id && !empty($recipients_string)) {
904
+    }
905
+    if (!$thread_id && !empty($recipients_string)) {
907 906
     drupal_set_title(t('Write new message to %recipient', array('%recipient' => $recipients_string)));
908
-  }
909
-  elseif (!$thread_id) {
907
+    }
908
+    elseif (!$thread_id) {
910 909
     drupal_set_title(t('Write new message'));
911
-  }
910
+    }
912 911
 
913
-  $form = array();
914
-  if (isset($form_state['privatemsg_preview'])) {
912
+    $form = array();
913
+    if (isset($form_state['privatemsg_preview'])) {
915 914
     $form['message_header'] = array(
916
-      '#type' => 'fieldset',
917
-      '#attributes' => array('class' => 'preview'),
915
+        '#type' => 'fieldset',
916
+        '#attributes' => array('class' => 'preview'),
918 917
     );
919 918
     $form['message_header']['message_preview'] = array(
920
-      '#value'  => $form_state['privatemsg_preview'],
919
+        '#value'  => $form_state['privatemsg_preview'],
921 920
     );
922
-  }
923
-  $form['privatemsg'] = array(
921
+    }
922
+    $form['privatemsg'] = array(
924 923
     '#type'               => 'fieldset',
925 924
     '#access'             => privatemsg_user_access('write privatemsg'),
926
-  );
927
-  $form['privatemsg']['author'] = array(
925
+    );
926
+    $form['privatemsg']['author'] = array(
928 927
     '#type' => 'value',
929 928
     '#value' => $user,
930
-  );
931
-  if (is_null($thread_id)) {
929
+    );
930
+    if (is_null($thread_id)) {
932 931
     $form['privatemsg']['recipient'] = array(
933
-      '#type'               => 'textfield',
934
-      '#title'              => t('To'),
935
-      '#description'        => t('Separate multiple names with commas.'),
936
-      '#default_value'      => $recipients_string,
937
-      '#required'           => TRUE,
938
-      '#weight'             => -10,
939
-      '#size'               => 50,
940
-      '#autocomplete_path'  => 'messages/user-name-autocomplete',
941
-      // Do not hardcode #maxlength, make it configurable by number of recipients, not their name length.
932
+        '#type'               => 'textfield',
933
+        '#title'              => t('To'),
934
+        '#description'        => t('Separate multiple names with commas.'),
935
+        '#default_value'      => $recipients_string,
936
+        '#required'           => TRUE,
937
+        '#weight'             => -10,
938
+        '#size'               => 50,
939
+        '#autocomplete_path'  => 'messages/user-name-autocomplete',
940
+        // Do not hardcode #maxlength, make it configurable by number of recipients, not their name length.
942 941
     );
943
-  }
944
-  $form['privatemsg']['subject'] = array(
942
+    }
943
+    $form['privatemsg']['subject'] = array(
945 944
     '#type'               => 'textfield',
946 945
     '#title'              => t('Subject'),
947 946
     '#size'               => 50,
948 947
     '#maxlength'          => 255,
949 948
     '#default_value'      => $subject,
950 949
     '#weight'             => -5,
951
-  );
952
-  $form['privatemsg']['body'] = array(
950
+    );
951
+    $form['privatemsg']['body'] = array(
953 952
     '#type'               => 'textarea',
954 953
     '#title'              => t('Message'),
955 954
     '#rows'               => 6,
956 955
     '#weight'             => 0,
957 956
     '#default_value'      => $body,
958 957
     '#resizable'          => TRUE,
959
-  );
960
-  $format = FILTER_FORMAT_DEFAULT;
961
-  // The input filter widget looses the format during preview, specify it
962
-  // explicitly.
963
-  if (isset($form_state['values']) && array_key_exists('format', $form_state['values'])) {
958
+    );
959
+    $format = FILTER_FORMAT_DEFAULT;
960
+    // The input filter widget looses the format during preview, specify it
961
+    // explicitly.
962
+    if (isset($form_state['values']) && array_key_exists('format', $form_state['values'])) {
964 963
     $format = $form_state['values']['format'];
965
-  }
966
-  $form['privatemsg']['format'] = filter_form($format);
967
-  $form['privatemsg']['preview'] = array(
964
+    }
965
+    $form['privatemsg']['format'] = filter_form($format);
966
+    $form['privatemsg']['preview'] = array(
968 967
     '#type'               => 'submit',
969 968
     '#value'              => t('Preview message'),
970 969
     '#submit'             => array('pm_preview'),
971 970
     '#validate'           => array('pm_send_validate'),
972 971
     '#weight'             => 10,
973
-  );
974
-  $form['privatemsg']['submit'] = array(
972
+    );
973
+    $form['privatemsg']['submit'] = array(
975 974
     '#type'               => 'submit',
976 975
     '#value'              => t('Send message'),
977 976
     '#submit'             => array('pm_send'),
978 977
     '#validate'           => array('pm_send_validate'),
979 978
     '#weight'             => 15,
980
-  );
981
-  $url = 'messages';
982
-  $title = t('Cancel');
983
-  if (isset($_REQUEST['destination'])) {
979
+    );
980
+    $url = 'messages';
981
+    $title = t('Cancel');
982
+    if (isset($_REQUEST['destination'])) {
984 983
     $url = $_REQUEST['destination'];
985
-  }
986
-  elseif (!is_null($thread_id)) {
984
+    }
985
+    elseif (!is_null($thread_id)) {
987 986
     $url = $_GET['q'];
988 987
     $title = t('Clear');
989
-  }
988
+    }
990 989
 
991
-  $form['privatemsg']['cancel'] = array(
990
+    $form['privatemsg']['cancel'] = array(
992 991
     '#value'              => l($title, $url, array('attributes' => array('id' => 'edit-cancel'))),
993 992
     '#weight'             => 20,
994
-  );
993
+    );
995 994
 
996
-  if (!is_null($thread_id)) {
995
+    if (!is_null($thread_id)) {
997 996
     $form['privatemsg']['thread_id'] = array(
998
-      '#type' => 'value',
999
-      '#value' => $thread_id,
997
+        '#type' => 'value',
998
+        '#value' => $thread_id,
1000 999
     );
1001 1000
     $form['privatemsg']['subject'] = array(
1002
-          '#type' => 'value',
1003
-          '#default_value' => $subject,
1001
+            '#type' => 'value',
1002
+            '#default_value' => $subject,
1004 1003
     );
1005 1004
     $recipients_string_themed = implode(', ', $to_themed);
1006 1005
     $form['privatemsg']['recipient_display'] = array(
1007
-      '#value' =>  '<p>'. t('<strong>Reply to thread</strong>:<br /> Recipients: !to', array('!to' => $recipients_string_themed)) .'</p>',
1008
-      '#weight' => -10,
1006
+        '#value' =>  '<p>'. t('<strong>Reply to thread</strong>:<br /> Recipients: !to', array('!to' => $recipients_string_themed)) .'</p>',
1007
+        '#weight' => -10,
1009 1008
     );
1010 1009
     if (empty($recipients_string)) {
1011
-      // If there are no valid recipients, unset the message reply form.
1012
-      $form['privatemsg']['#access'] = FALSE;
1010
+        // If there are no valid recipients, unset the message reply form.
1011
+        $form['privatemsg']['#access'] = FALSE;
1012
+    }
1013 1013
     }
1014
-  }
1015
-  $form['privatemsg']['read_all'] = array(
1014
+    $form['privatemsg']['read_all'] = array(
1016 1015
     '#type'  => 'value',
1017 1016
     '#value' => $read_all,
1018
-  );
1019
-  return $form;
1017
+    );
1018
+    return $form;
1020 1019
 }
1021 1020
 
1022 1021
 function pm_send_validate($form, &$form_state) {
1023
-  // The actual message that is being sent, we create this during validation and pass to submit to send out.
1024
-  $message = $form_state['values'];
1025
-  $message['timestamp'] = time();
1026
-  // Avoid subjects which only consist of a space as these can not be clicked.
1027
-  $message['subject'] = trim($message['subject']);
1022
+    // The actual message that is being sent, we create this during validation and pass to submit to send out.
1023
+    $message = $form_state['values'];
1024
+    $message['timestamp'] = time();
1025
+    // Avoid subjects which only consist of a space as these can not be clicked.
1026
+    $message['subject'] = trim($message['subject']);
1028 1027
 
1029 1028
 
1030
-  $trimed_body = trim(truncate_utf8(strip_tags($message['body']), 50, TRUE, TRUE));
1031
-  if (empty($message['subject']) && !empty($trimed_body)) {
1029
+    $trimed_body = trim(truncate_utf8(strip_tags($message['body']), 50, TRUE, TRUE));
1030
+    if (empty($message['subject']) && !empty($trimed_body)) {
1032 1031
     $message['subject'] = $trimed_body;
1033
-  }
1034
-  // Only parse the user string for a new thread.
1035
-  if (!isset($message['thread_id'])) {
1032
+    }
1033
+    // Only parse the user string for a new thread.
1034
+    if (!isset($message['thread_id'])) {
1036 1035
     list($message['recipients'], $invalid) = _privatemsg_parse_userstring($message['recipient']);
1037
-  }
1038
-  else {
1036
+    }
1037
+    else {
1039 1038
     // Load participants.
1040 1039
     $message['recipients'] = _privatemsg_load_thread_participants($message['thread_id']);
1041 1040
     // Remove author.
1042 1041
     if (isset($message['recipients'][$message['author']->uid]) && count($message['recipients']) > 1) {
1043
-      unset($message['recipients'][$message['author']->uid]);
1042
+        unset($message['recipients'][$message['author']->uid]);
1043
+    }
1044 1044
     }
1045
-  }
1046 1045
 
1047
-  $validated = _privatemsg_validate_message($message, TRUE);
1048
-  foreach ($validated['messages'] as $type => $text) {
1046
+    $validated = _privatemsg_validate_message($message, TRUE);
1047
+    foreach ($validated['messages'] as $type => $text) {
1049 1048
     drupal_set_message($text, $type);
1050
-  }
1051
-  $form_state['validate_built_message'] = $message;
1052
-  if (!empty($invalid)) {
1049
+    }
1050
+    $form_state['validate_built_message'] = $message;
1051
+    if (!empty($invalid)) {
1053 1052
     drupal_set_message(t('The following users will not receive this private message: @invalid', array('@invalid' => implode(", ", $invalid))), 'error');
1054
-  }
1053
+    }
1055 1054
 }
1056 1055
 
1057 1056
 /**
@@ -1061,15 +1060,15 @@  discard block
 block discarded – undo
1061 1060
  *   Thread ID for wich the participants should be loaded.
1062 1061
  */
1063 1062
 function _privatemsg_load_thread_participants($thread_id) {
1064
-  $query = _privatemsg_assemble_query('participants', $thread_id);
1065
-  $result = db_query($query['query']);
1066
-  $participants = array();
1067
-  while ($uid = db_fetch_object($result)) {
1063
+    $query = _privatemsg_assemble_query('participants', $thread_id);
1064
+    $result = db_query($query['query']);
1065
+    $participants = array();
1066
+    while ($uid = db_fetch_object($result)) {
1068 1067
     if (($recipient = user_load($uid->uid))) {
1069
-      $participants[$recipient->uid] = $recipient;
1068
+        $participants[$recipient->uid] = $recipient;
1069
+    }
1070 1070
     }
1071
-  }
1072
-  return $participants;
1071
+    return $participants;
1073 1072
 }
1074 1073
 
1075 1074
 /**
@@ -1085,68 +1084,68 @@  discard block
 block discarded – undo
1085 1084
  *   with invalid names.
1086 1085
  */
1087 1086
 function _privatemsg_parse_userstring($input) {
1088
-  if (is_string($input)) {
1087
+    if (is_string($input)) {
1089 1088
     $input = explode(',', $input);
1090
-  }
1089
+    }
1091 1090
 
1092
-  // Start working through the input array.
1093
-  $invalid = array();
1094
-  $recipients = array();
1095
-  foreach ($input as $string) {
1091
+    // Start working through the input array.
1092
+    $invalid = array();
1093
+    $recipients = array();
1094
+    foreach ($input as $string) {
1096 1095
     $string = trim($string);
1097 1096
     if (!empty($string)) { // We don't care about white space names.
1098 1097
 
1099
-      // First, check if another module is able to resolve the string into an
1100
-      // user object.
1101
-      foreach (module_implements('privatemsg_name_lookup') as $module) {
1098
+        // First, check if another module is able to resolve the string into an
1099
+        // user object.
1100
+        foreach (module_implements('privatemsg_name_lookup') as $module) {
1102 1101
         $function = $module . '_privatemsg_name_lookup';
1103 1102
         if (($recipient = $function($string)) && is_object($recipient)) {
1104
-          // If there is a match, continue with the next input string.
1105
-          $recipients[$recipient->uid] = $recipient;
1106
-          continue 2;
1103
+            // If there is a match, continue with the next input string.
1104
+            $recipients[$recipient->uid] = $recipient;
1105
+            continue 2;
1107 1106
         }
1108
-      }
1109
-      // Fall back to the default username lookup.
1110
-      if (!$error = module_invoke('user', 'validate_name', $string)) {
1107
+        }
1108
+        // Fall back to the default username lookup.
1109
+        if (!$error = module_invoke('user', 'validate_name', $string)) {
1111 1110
         // String is a valid username, look it up.
1112 1111
         if ($recipient = user_load(array('name' => $string))) {
1113
-          $recipients[$recipient->uid] = $recipient;
1114
-          continue;
1112
+            $recipients[$recipient->uid] = $recipient;
1113
+            continue;
1114
+        }
1115 1115
         }
1116
-      }
1117
-      $invalid[$string] = $string;
1116
+        $invalid[$string] = $string;
1117
+    }
1118 1118
     }
1119
-  }
1120 1119
 
1121
-  return array($recipients, $invalid);
1120
+    return array($recipients, $invalid);
1122 1121
 }
1123 1122
 
1124 1123
 /**
1125 1124
  * Submit callback for the privatemsg_new form.
1126 1125
  */
1127 1126
 function pm_send($form, &$form_state) {
1128
-  $status = _privatemsg_send($form_state['validate_built_message']);
1129
-  // Load usernames to which the message was sent to.
1130
-  $recipient_names = array();
1131
-  foreach ($form_state['validate_built_message']['recipients'] as $recipient) {
1127
+    $status = _privatemsg_send($form_state['validate_built_message']);
1128
+    // Load usernames to which the message was sent to.
1129
+    $recipient_names = array();
1130
+    foreach ($form_state['validate_built_message']['recipients'] as $recipient) {
1132 1131
     $recipient_names[] = theme('username', $recipient);
1133
-  }
1134
-  if ($status !== FALSE )  {
1132
+    }
1133
+    if ($status !== FALSE )  {
1135 1134
     drupal_set_message(t('A message has been sent to !recipients.', array('!recipients' => implode(', ', $recipient_names))));
1136
-  }
1137
-  else {
1135
+    }
1136
+    else {
1138 1137
     drupal_set_message(t('An attempt to send a message <em>may have failed</em> when sending to !recipients.', array('!recipients' => implode(', ', $recipient_names))), 'error');
1139
-  }
1138
+    }
1140 1139
 }
1141 1140
 
1142 1141
 function pm_preview($form, &$form_state) {
1143 1142
 
1144 1143
     drupal_validate_form($form['form_id']['#value'], $form, $form_state);
1145 1144
     if (!form_get_errors()) {
1146
-      $form_state['privatemsg_preview'] = theme('privatemsg_view', $form_state['validate_built_message']);
1145
+        $form_state['privatemsg_preview'] = theme('privatemsg_view', $form_state['validate_built_message']);
1147 1146
     }
1148 1147
 
1149
-  $form_state['rebuild'] = TRUE; // this forces our form to be rebuilt instead of being submitted.
1148
+    $form_state['rebuild'] = TRUE; // this forces our form to be rebuilt instead of being submitted.
1150 1149
 }
1151 1150
 
1152 1151
 /**
@@ -1167,65 +1166,65 @@  discard block
 block discarded – undo
1167 1166
  */
1168 1167
 
1169 1168
 function privatemsg_sql_list(&$fragments, $account, $argument = 'list') {
1170
-  $fragments['primary_table'] = '{pm_message} pm';
1171
-
1172
-  // Load enabled columns.
1173
-  $fields = array_filter(variable_get('privatemsg_display_fields', array('participants')));
1174
-
1175
-  // Required columns.
1176
-  $fragments['select'][]      = 'pmi.thread_id';
1177
-  // We have to use MIN as the subject might not be the same in some threads.
1178
-  // MIN() does not have a useful meaning except that it helps to correctly
1179
-  // aggregate the thread on PostgreSQL.
1180
-  $fragments['select'][]      = 'MIN(pm.subject) as subject';
1181
-  $fragments['select'][]      = 'MAX(pm.timestamp) as last_updated';
1182
-  // We use SUM so that we can count the number of unread messages.
1183
-  $fragments['select'][]      = 'SUM(pmi.is_new) as is_new';
1184
-
1185
-  // Select number of messages in the thread if the count is
1186
-  // set to be displayed.
1187
-  if (in_array('count', $fields)) {
1169
+    $fragments['primary_table'] = '{pm_message} pm';
1170
+
1171
+    // Load enabled columns.
1172
+    $fields = array_filter(variable_get('privatemsg_display_fields', array('participants')));
1173
+
1174
+    // Required columns.
1175
+    $fragments['select'][]      = 'pmi.thread_id';
1176
+    // We have to use MIN as the subject might not be the same in some threads.
1177
+    // MIN() does not have a useful meaning except that it helps to correctly
1178
+    // aggregate the thread on PostgreSQL.
1179
+    $fragments['select'][]      = 'MIN(pm.subject) as subject';
1180
+    $fragments['select'][]      = 'MAX(pm.timestamp) as last_updated';
1181
+    // We use SUM so that we can count the number of unread messages.
1182
+    $fragments['select'][]      = 'SUM(pmi.is_new) as is_new';
1183
+
1184
+    // Select number of messages in the thread if the count is
1185
+    // set to be displayed.
1186
+    if (in_array('count', $fields)) {
1188 1187
     $fragments['select'][]      = 'COUNT(distinct pmi.mid) as count';
1189
-  }
1190
-  if (in_array('participants', $fields)) {
1188
+    }
1189
+    if (in_array('participants', $fields)) {
1191 1190
     // Query for a string with uid's, for example "1,6,7".
1192 1191
     // @todo: Replace this with a single query similiar to the tag list.
1193 1192
     if ($GLOBALS['db_type'] == 'pgsql') {
1194
-      // PostgreSQL does not know GROUP_CONCAT, so a subquery is required.
1195
-      $fragments['select'][]      = "array_to_string(array(SELECT DISTINCT textin(int4out(pmia.uid))
1193
+        // PostgreSQL does not know GROUP_CONCAT, so a subquery is required.
1194
+        $fragments['select'][]      = "array_to_string(array(SELECT DISTINCT textin(int4out(pmia.uid))
1196 1195
                                                             FROM {pm_index} pmia
1197 1196
                                                             WHERE pmia.thread_id = pmi.thread_id), ',') AS participants";
1198 1197
     }
1199 1198
     else {
1200
-      $fragments['select'][]      = '(SELECT GROUP_CONCAT(DISTINCT pmia.uid SEPARATOR ",")
1199
+        $fragments['select'][]      = '(SELECT GROUP_CONCAT(DISTINCT pmia.uid SEPARATOR ",")
1201 1200
                                                             FROM {pm_index} pmia
1202 1201
                                                             WHERE pmia.thread_id = pmi.thread_id) AS participants';
1203 1202
     }
1204
-  }
1205
-  if (in_array('thread_started', $fields)) {
1203
+    }
1204
+    if (in_array('thread_started', $fields)) {
1206 1205
     $fragments['select'][]      = 'MIN(pm.timestamp) as thread_started';
1207
-  }
1206
+    }
1208 1207
 
1209
-  $fragments['inner_join'][]  = 'INNER JOIN {pm_index} pmi ON pm.mid = pmi.mid';
1208
+    $fragments['inner_join'][]  = 'INNER JOIN {pm_index} pmi ON pm.mid = pmi.mid';
1210 1209
 
1211
-  // Only load undeleted messages of the current user and group by thread.
1212
-  $fragments['where'][]       = 'pmi.uid = %d';
1213
-  $fragments['query_args']['where'][]  = $account->uid;
1214
-  $fragments['where'][]       = 'pmi.deleted = 0';
1215
-  $fragments['group_by'][]    = 'pmi.thread_id';
1210
+    // Only load undeleted messages of the current user and group by thread.
1211
+    $fragments['where'][]       = 'pmi.uid = %d';
1212
+    $fragments['query_args']['where'][]  = $account->uid;
1213
+    $fragments['where'][]       = 'pmi.deleted = 0';
1214
+    $fragments['group_by'][]    = 'pmi.thread_id';
1216 1215
 
1217
-  $order_by_first = 'MAX(pmi.is_new) DESC, ';
1218
-  // MySQL 4.1 does not allow to order by aggregate functions. MAX() is used
1219
-  // to avoid a ordering bug with multiple new messages.
1220
-  if ($GLOBALS['db_type'] != 'pgsql' && version_compare(db_version(), '5.0.0') < 0) {
1216
+    $order_by_first = 'MAX(pmi.is_new) DESC, ';
1217
+    // MySQL 4.1 does not allow to order by aggregate functions. MAX() is used
1218
+    // to avoid a ordering bug with multiple new messages.
1219
+    if ($GLOBALS['db_type'] != 'pgsql' && version_compare(db_version(), '5.0.0') < 0) {
1221 1220
     $order_by_first = 'is_new DESC, ';
1222
-  }
1221
+    }
1223 1222
 
1224
-  // tablesort_sql() generates a ORDER BY string. However, the "ORDER BY " part 
1225
-  // is not needed and added by the query builder. Discard the first 9
1226
-  // characters of the string.
1227
-  $order_by = drupal_substr(tablesort_sql(_privatemsg_list_headers( FALSE, array_merge(array('subject', 'last_updated'), $fields)), $order_by_first), 9);
1228
-  $fragments['order_by'][]  = $order_by;
1223
+    // tablesort_sql() generates a ORDER BY string. However, the "ORDER BY " part 
1224
+    // is not needed and added by the query builder. Discard the first 9
1225
+    // characters of the string.
1226
+    $order_by = drupal_substr(tablesort_sql(_privatemsg_list_headers( FALSE, array_merge(array('subject', 'last_updated'), $fields)), $order_by_first), 9);
1227
+    $fragments['order_by'][]  = $order_by;
1229 1228
 }
1230 1229
 
1231 1230
 /**
@@ -1239,27 +1238,27 @@  discard block
 block discarded – undo
1239 1238
  *   Account for which the messages should be loaded.
1240 1239
  */
1241 1240
 function privatemsg_sql_load(&$fragments, $pmids, $account = NULL) {
1242
-  $fragments['primary_table'] = '{pm_message} pm';
1243
-
1244
-  $fragments['select'][]      = "pm.mid";
1245
-  $fragments['select'][]      = "pm.author";
1246
-  $fragments['select'][]      = "pm.subject";
1247
-  $fragments['select'][]      = "pm.body";
1248
-  $fragments['select'][]      = "pm.timestamp";
1249
-  $fragments['select'][]      = "pm.format";
1250
-  $fragments['select'][]      = "pmi.is_new";
1251
-  $fragments['select'][]      = "pmi.thread_id";
1252
-
1253
-  $fragments['inner_join'][]  = 'INNER JOIN {pm_index} pmi ON pm.mid = pmi.mid';
1254
-  // Use IN() to load multiple messages at the same time.
1255
-  $fragments['where'][]       = 'pmi.mid IN (' . db_placeholders($pmids) . ')';
1256
-  $fragments['query_args']['where']  += $pmids;
1257
-  if ($account) {
1241
+    $fragments['primary_table'] = '{pm_message} pm';
1242
+
1243
+    $fragments['select'][]      = "pm.mid";
1244
+    $fragments['select'][]      = "pm.author";
1245
+    $fragments['select'][]      = "pm.subject";
1246
+    $fragments['select'][]      = "pm.body";
1247
+    $fragments['select'][]      = "pm.timestamp";
1248
+    $fragments['select'][]      = "pm.format";
1249
+    $fragments['select'][]      = "pmi.is_new";
1250
+    $fragments['select'][]      = "pmi.thread_id";
1251
+
1252
+    $fragments['inner_join'][]  = 'INNER JOIN {pm_index} pmi ON pm.mid = pmi.mid';
1253
+    // Use IN() to load multiple messages at the same time.
1254
+    $fragments['where'][]       = 'pmi.mid IN (' . db_placeholders($pmids) . ')';
1255
+    $fragments['query_args']['where']  += $pmids;
1256
+    if ($account) {
1258 1257
     $fragments['where'][]       = 'pmi.uid = %d';
1259 1258
     $fragments['query_args']['where'][]  = $account->uid;
1260
-  }
1261
-  $fragments['order_by'][] = 'pm.timestamp ASC';
1262
-  $fragments['order_by'][] = 'pm.mid ASC';
1259
+    }
1260
+    $fragments['order_by'][] = 'pm.timestamp ASC';
1261
+    $fragments['order_by'][] = 'pm.mid ASC';
1263 1262
 }
1264 1263
 
1265 1264
 /**
@@ -1275,30 +1274,30 @@  discard block
 block discarded – undo
1275 1274
  *   Deleted messages are only loaded if this is set to TRUE.
1276 1275
  */
1277 1276
 function privatemsg_sql_messages(&$fragments, $threads, $account = NULL, $load_all = FALSE) {
1278
-  $fragments['primary_table'] = '{pm_index} pmi';
1277
+    $fragments['primary_table'] = '{pm_index} pmi';
1279 1278
 
1280
-  $fragments['select'][]      = 'pmi.mid';
1281
-  $fragments['where'][]       = 'pmi.thread_id IN ('. db_placeholders($threads) .')';
1282
-  $fragments['query_args']['where']   += $threads;
1283
-  $fragments['inner_join'][]  = 'INNER JOIN {pm_message} pm ON (pm.mid = pmi.mid)';
1284
-  if ($account) {
1279
+    $fragments['select'][]      = 'pmi.mid';
1280
+    $fragments['where'][]       = 'pmi.thread_id IN ('. db_placeholders($threads) .')';
1281
+    $fragments['query_args']['where']   += $threads;
1282
+    $fragments['inner_join'][]  = 'INNER JOIN {pm_message} pm ON (pm.mid = pmi.mid)';
1283
+    if ($account) {
1285 1284
     // Only load the user's messages.
1286 1285
     $fragments['where'][]     = 'pmi.uid = %d';
1287 1286
     $fragments['query_args']['where'][]  = $account->uid;
1288
-  }
1289
-  if (!$load_all) {
1287
+    }
1288
+    if (!$load_all) {
1290 1289
     // Also load deleted messages when requested.
1291 1290
     $fragments['where'][]     = 'pmi.deleted = 0';
1292
-  }
1293
-  // Only load each mid once.
1294
-  $fragments['group_by'][]    = 'pmi.mid';
1295
-  $fragments['group_by'][]    = 'pm.timestamp';
1291
+    }
1292
+    // Only load each mid once.
1293
+    $fragments['group_by'][]    = 'pmi.mid';
1294
+    $fragments['group_by'][]    = 'pm.timestamp';
1296 1295
 
1297
-  // Order by timestamp first.
1298
-  $fragments['order_by'][]    = 'pm.timestamp ASC';
1299
-  // If there are multiple inserts during the same second (tests, for example)
1300
-  // sort by mid second to have them in the same order as they were saved.
1301
-  $fragments['order_by'][]    = 'pmi.mid ASC';
1296
+    // Order by timestamp first.
1297
+    $fragments['order_by'][]    = 'pm.timestamp ASC';
1298
+    // If there are multiple inserts during the same second (tests, for example)
1299
+    // sort by mid second to have them in the same order as they were saved.
1300
+    $fragments['order_by'][]    = 'pmi.mid ASC';
1302 1301
 
1303 1302
 }
1304 1303
 
@@ -1311,16 +1310,16 @@  discard block
 block discarded – undo
1311 1310
  *   Thread id from which the participants should be loaded.
1312 1311
  */
1313 1312
 function privatemsg_sql_participants(&$fragments, $thread_id) {
1314
-  $fragments['primary_table'] = '{pm_index} pmi';
1313
+    $fragments['primary_table'] = '{pm_index} pmi';
1315 1314
 
1316
-  // Only load each participant once since they are listed as recipient for
1317
-  // every message of that thread.
1318
-  $fragments['select'][]      = 'DISTINCT(pmi.uid) AS uid';
1319
-  $fragments['select'][]      = 'u.name AS name';
1315
+    // Only load each participant once since they are listed as recipient for
1316
+    // every message of that thread.
1317
+    $fragments['select'][]      = 'DISTINCT(pmi.uid) AS uid';
1318
+    $fragments['select'][]      = 'u.name AS name';
1320 1319
 
1321
-  $fragments['inner_join'][]  = 'INNER JOIN {users} u ON (u.uid = pmi.uid)';
1322
-  $fragments['where'][]       = 'pmi.thread_id = %d';
1323
-  $fragments['query_args']['where'][]  = $thread_id;
1320
+    $fragments['inner_join'][]  = 'INNER JOIN {users} u ON (u.uid = pmi.uid)';
1321
+    $fragments['where'][]       = 'pmi.thread_id = %d';
1322
+    $fragments['query_args']['where'][]  = $thread_id;
1324 1323
 }
1325 1324
 
1326 1325
 /**
@@ -1332,15 +1331,15 @@  discard block
 block discarded – undo
1332 1331
  *   User object for which the messages are being counted.
1333 1332
  */
1334 1333
 function privatemsg_sql_unread_count(&$fragments, $account) {
1335
-  $fragments['primary_table'] = '{pm_index} pmi';
1334
+    $fragments['primary_table'] = '{pm_index} pmi';
1336 1335
 
1337
-  $fragments['select'][]      = 'COUNT(DISTINCT thread_id) as unread_count';
1336
+    $fragments['select'][]      = 'COUNT(DISTINCT thread_id) as unread_count';
1338 1337
 
1339
-  // Only count new messages that have not been deleted.
1340
-  $fragments['where'][]       = 'pmi.deleted = 0';
1341
-  $fragments['where'][]       = 'pmi.is_new = 1';
1342
-  $fragments['where'][]       = 'pmi.uid = %d';
1343
-  $fragments['query_args']['where'][]  = $account->uid;
1338
+    // Only count new messages that have not been deleted.
1339
+    $fragments['where'][]       = 'pmi.deleted = 0';
1340
+    $fragments['where'][]       = 'pmi.is_new = 1';
1341
+    $fragments['where'][]       = 'pmi.uid = %d';
1342
+    $fragments['query_args']['where'][]  = $account->uid;
1344 1343
 }
1345 1344
 
1346 1345
 /**
@@ -1354,19 +1353,19 @@  discard block
 block discarded – undo
1354 1353
  *   Array of names not to be used as suggestions.
1355 1354
  */
1356 1355
 function privatemsg_sql_autocomplete(&$fragments, $search, $names) {
1357
-  $fragments['primary_table'] = '{users} u';
1358
-  $fragments['select'][] = 'u.name';
1359
-  // Escape the % to get it through the placeholder replacement.
1360
-  $fragments['where'][] = "u.name LIKE '%s'";
1361
-  $fragments['query_args']['where'][] = $search .'%%';
1362
-  if (!empty($names)) {
1356
+    $fragments['primary_table'] = '{users} u';
1357
+    $fragments['select'][] = 'u.name';
1358
+    // Escape the % to get it through the placeholder replacement.
1359
+    $fragments['where'][] = "u.name LIKE '%s'";
1360
+    $fragments['query_args']['where'][] = $search .'%%';
1361
+    if (!empty($names)) {
1363 1362
     // If there are already names selected, exclude them from the suggestions.
1364 1363
     $fragments['where'][] = "u.name NOT IN (". db_placeholders($names, 'text') .")";
1365 1364
     $fragments['query_args']['where'] += $names;
1366
-  }
1367
-  // Only load active users and sort them by name.
1368
-  $fragments['where'][] = 'u.status <> 0';
1369
-  $fragments['order_by'][] = 'u.name ASC';
1365
+    }
1366
+    // Only load active users and sort them by name.
1367
+    $fragments['where'][] = 'u.status <> 0';
1368
+    $fragments['order_by'][] = 'u.name ASC';
1370 1369
 }
1371 1370
 
1372 1371
 /**
@@ -1378,24 +1377,24 @@  discard block
 block discarded – undo
1378 1377
  *   Select messages older than x days.
1379 1378
  */
1380 1379
 function privatemsg_sql_deleted(&$fragments, $days) {
1381
-  $fragments['primary_table'] = '{pm_message} pm';
1380
+    $fragments['primary_table'] = '{pm_message} pm';
1382 1381
 
1383
-  $fragments['select'][] = 'pm.mid';
1384
-  // The lowest value is higher than 0 if all recipients have deleted a message.
1385
-  $fragments['select'][] = 'MIN(pmi.deleted) as is_deleted';
1386
-  // The time the most recent deletion happened.
1387
-  $fragments['select'][] = 'MAX(pmi.deleted) as last_deleted';
1382
+    $fragments['select'][] = 'pm.mid';
1383
+    // The lowest value is higher than 0 if all recipients have deleted a message.
1384
+    $fragments['select'][] = 'MIN(pmi.deleted) as is_deleted';
1385
+    // The time the most recent deletion happened.
1386
+    $fragments['select'][] = 'MAX(pmi.deleted) as last_deleted';
1388 1387
 
1389
-  $fragments['inner_join'][] = 'INNER JOIN {pm_index} pmi ON (pmi.mid = pm.mid)';
1388
+    $fragments['inner_join'][] = 'INNER JOIN {pm_index} pmi ON (pmi.mid = pm.mid)';
1390 1389
 
1391
-  $fragments['group_by'][] = 'pm.mid';
1390
+    $fragments['group_by'][] = 'pm.mid';
1392 1391
 
1393
-  // Ignore messages that have not been deleted by all users.
1394
-  $fragments['having'][] = 'MIN(pmi.deleted) > 0';
1392
+    // Ignore messages that have not been deleted by all users.
1393
+    $fragments['having'][] = 'MIN(pmi.deleted) > 0';
1395 1394
 
1396
-  // Only select messages that have been deleted more than n days ago.
1397
-  $fragments['having'][] = 'MAX(pmi.deleted) < %d';
1398
-  $fragments['query_args']['having'][] = time() - $days * 86400;
1395
+    // Only select messages that have been deleted more than n days ago.
1396
+    $fragments['having'][] = 'MAX(pmi.deleted) < %d';
1397
+    $fragments['query_args']['having'][] = time() - $days * 86400;
1399 1398
 }
1400 1399
 
1401 1400
 /**
@@ -1408,192 +1407,192 @@  discard block
 block discarded – undo
1408 1407
  * Prevents usernames from being used and/or suggested twice.
1409 1408
  */
1410 1409
 function privatemsg_user_name_autocomplete($string) {
1411
-  $names = array();
1412
-  // 1: Parse $string and build list of valid user names.
1413
-  $fragments = explode(',', $string);
1414
-  foreach ($fragments as $index => $name) {
1410
+    $names = array();
1411
+    // 1: Parse $string and build list of valid user names.
1412
+    $fragments = explode(',', $string);
1413
+    foreach ($fragments as $index => $name) {
1415 1414
     if ($name = trim($name)) {
1416
-      $names[$name] = $name;
1417
-    }
1418
-  }
1419
-  // By using user_validate_user we can ensure that names included in $names are at least logisticaly possible.
1420
-  // 2: Find the next user name suggestion.
1421
-  $fragment = array_pop($names);
1422
-  $matches = array();
1423
-  if (!empty($fragment)) {
1415
+        $names[$name] = $name;
1416
+    }
1417
+    }
1418
+    // By using user_validate_user we can ensure that names included in $names are at least logisticaly possible.
1419
+    // 2: Find the next user name suggestion.
1420
+    $fragment = array_pop($names);
1421
+    $matches = array();
1422
+    if (!empty($fragment)) {
1424 1423
     $query = _privatemsg_assemble_query('autocomplete', $fragment, $names);
1425 1424
     $result = db_query_range($query['query'], $fragment, 0, 10);
1426 1425
     $prefix = count($names) ? implode(", ", $names) .", " : '';
1427 1426
     // 3: Build proper suggestions and print.
1428 1427
     while ($user = db_fetch_object($result)) {
1429
-      $matches[$prefix . $user->name .", "] = $user->name;
1428
+        $matches[$prefix . $user->name .", "] = $user->name;
1430 1429
     }
1431
-  }
1432
-  // convert to object to prevent drupal bug, see http://drupal.org/node/175361
1433
-  drupal_json((object)$matches);
1430
+    }
1431
+    // convert to object to prevent drupal bug, see http://drupal.org/node/175361
1432
+    drupal_json((object)$matches);
1434 1433
 }
1435 1434
 
1436 1435
 function privatemsg_user($op, &$edit, &$account, $category = NULL) {
1437
-  global $user;
1436
+    global $user;
1438 1437
 
1439
-  switch ($op) {
1438
+    switch ($op) {
1440 1439
     case 'view':
1441 1440
       if ($url = privatemsg_get_link(array($account))) {
1442 1441
         $account->content['privatemsg_send_new_message'] = array(
1443
-          '#type'   => 'markup',
1444
-          '#value'  => l(t('Send this user a message'), $url, array('query' => drupal_get_destination())),
1445
-          '#weight' => 10,
1442
+            '#type'   => 'markup',
1443
+            '#value'  => l(t('Send this user a message'), $url, array('query' => drupal_get_destination())),
1444
+            '#weight' => 10,
1446 1445
         );
1447
-      }
1448
-      break;
1446
+        }
1447
+        break;
1449 1448
     case 'login':
1450 1449
       if (variable_get('privatemsg_display_loginmessage', TRUE) && privatemsg_user_access()) {
1451 1450
         $count = privatemsg_unread_count();
1452 1451
         if ($count) {
1453
-          drupal_set_message(format_plural($count, 'You have <a href="@messages">1 unread message</a>.', 'You have <a href="@messages">@count unread messages</a>', array('@messages' => url('messages'))));
1452
+            drupal_set_message(format_plural($count, 'You have <a href="@messages">1 unread message</a>.', 'You have <a href="@messages">@count unread messages</a>', array('@messages' => url('messages'))));
1454 1453
         }
1455
-      }
1456
-      break;
1454
+        }
1455
+        break;
1457 1456
     case 'delete':
1458 1457
 
1459 1458
       // Load all mids of the messages the user wrote.
1460 1459
       $result = db_query("SELECT mid FROM {pm_message} WHERE author = %d", $account->uid);
1461
-      $mids = array();
1462
-      while ($row = db_fetch_array($result)) {
1460
+        $mids = array();
1461
+        while ($row = db_fetch_array($result)) {
1463 1462
         $mids[] = $row['mid'];
1464
-      }
1463
+        }
1465 1464
 
1466
-      // Delete messages the user wrote.
1467
-      db_query('DELETE FROM {pm_message} WHERE author = %d', $account->uid);
1465
+        // Delete messages the user wrote.
1466
+        db_query('DELETE FROM {pm_message} WHERE author = %d', $account->uid);
1468 1467
 
1469
-      if (!empty($mids)) {
1468
+        if (!empty($mids)) {
1470 1469
         // Delete recipient entries in {pm_index} of the messages the user wrote.
1471 1470
         db_query('DELETE FROM {pm_index} WHERE mid IN (' . db_placeholders($mids) . ')', $mids);
1472
-      }
1471
+        }
1473 1472
 
1474
-      // Delete recipient entries of that user.
1475
-      db_query('DELETE FROM {pm_index} WHERE uid = %d', $account->uid);
1476
-      break;
1477
-  }
1473
+        // Delete recipient entries of that user.
1474
+        db_query('DELETE FROM {pm_index} WHERE uid = %d', $account->uid);
1475
+        break;
1476
+    }
1478 1477
 }
1479 1478
 
1480 1479
 function privatemsg_block($op = 'list', $delta = 0, $edit = array()) {
1481
-  if ('list' == $op) {
1480
+    if ('list' == $op) {
1482 1481
     $blocks = array();
1483 1482
     $blocks['privatemsg-menu'] = array(
1484
-      'info' => t('Privatemsg links'),
1485
-      'cache' => BLOCK_NO_CACHE,
1483
+        'info' => t('Privatemsg links'),
1484
+        'cache' => BLOCK_NO_CACHE,
1486 1485
     );
1487 1486
     $blocks['privatemsg-new'] = array(
1488
-      'info' => t('New message indication'),
1489
-      'cache' => BLOCK_NO_CACHE,
1487
+        'info' => t('New message indication'),
1488
+        'cache' => BLOCK_NO_CACHE,
1490 1489
     );
1491 1490
 
1492 1491
     return $blocks;
1493
-  }
1494
-  elseif ('view' == $op) {
1492
+    }
1493
+    elseif ('view' == $op) {
1495 1494
     $block = array();
1496 1495
     switch ($delta) {
1497
-      case 'privatemsg-menu':
1496
+        case 'privatemsg-menu':
1498 1497
         $block = _privatemsg_block_menu();
1499 1498
         break;
1500
-      case 'privatemsg-new':
1499
+        case 'privatemsg-new':
1501 1500
         $block = _privatemsg_block_new();
1502 1501
         break;
1503 1502
     }
1504 1503
     return $block;
1505
-  }
1504
+    }
1506 1505
 }
1507 1506
 
1508 1507
 function privatemsg_title_callback($title = NULL) {
1509
-  $count = privatemsg_unread_count();
1508
+    $count = privatemsg_unread_count();
1510 1509
 
1511
-  if ($count > 0) {
1510
+    if ($count > 0) {
1512 1511
     return format_plural($count, 'Messages (1 new)', 'Messages (@count new)');
1513
-  }
1514
-  return t('Messages');
1512
+    }
1513
+    return t('Messages');
1515 1514
 }
1516 1515
 
1517 1516
 
1518 1517
 function _privatemsg_block_new() {
1519
-  $block = array();
1518
+    $block = array();
1520 1519
 
1521
-  if (!privatemsg_user_access()) {
1520
+    if (!privatemsg_user_access()) {
1522 1521
     return $block;
1523
-  }
1522
+    }
1524 1523
 
1525
-  $count = privatemsg_unread_count();
1526
-  if ($count) {
1524
+    $count = privatemsg_unread_count();
1525
+    if ($count) {
1527 1526
     $block = array(
1528
-      'subject' => format_plural($count, 'New message', 'New messages'),
1529
-      'content' => theme('privatemsg_new_block', $count),
1527
+        'subject' => format_plural($count, 'New message', 'New messages'),
1528
+        'content' => theme('privatemsg_new_block', $count),
1530 1529
     );
1531 1530
     return $block;
1532
-  }
1533
-  return array();
1531
+    }
1532
+    return array();
1534 1533
 }
1535 1534
 
1536 1535
 function _privatemsg_block_menu() {
1537
-  $block = array();
1536
+    $block = array();
1538 1537
 
1539
-  $links = array();
1540
-  if (privatemsg_user_access('write privatemsg')) {
1538
+    $links = array();
1539
+    if (privatemsg_user_access('write privatemsg')) {
1541 1540
     $links[] = l(t('Write new message'), 'messages/new');
1542
-  }
1543
-  if (privatemsg_user_access('read privatemsg') || privatemsg_user_access('read all private messages') ) {
1541
+    }
1542
+    if (privatemsg_user_access('read privatemsg') || privatemsg_user_access('read all private messages') ) {
1544 1543
     $links[] = l(privatemsg_title_callback(), 'messages');
1545
-  }
1546
-  if ( count( $links ) ) {
1544
+    }
1545
+    if ( count( $links ) ) {
1547 1546
     $block = array(
1548
-      'subject' => t('Private messages'),
1549
-      'content' => theme('item_list', $links),
1547
+        'subject' => t('Private messages'),
1548
+        'content' => theme('item_list', $links),
1550 1549
     );
1551
-  }
1552
-  return $block;
1550
+    }
1551
+    return $block;
1553 1552
 }
1554 1553
 
1555 1554
 function privatemsg_delete($form_state, $thread, $message) {
1556
-  $form['pmid'] = array(
1555
+    $form['pmid'] = array(
1557 1556
     '#type' => 'value',
1558 1557
     '#value' => $message['mid'],
1559
-  );
1560
-  $form['delete_destination'] = array(
1558
+    );
1559
+    $form['delete_destination'] = array(
1561 1560
     '#type' => 'value',
1562 1561
     '#value' => count($thread['messages']) > 1 ? 'messages/view/' . $message['thread_id'] : 'messages',
1563
-  );
1562
+    );
1564 1563
 
1565
-  if (privatemsg_user_access('read all private messages')) {
1564
+    if (privatemsg_user_access('read all private messages')) {
1566 1565
     $form['delete_options'] = array(
1567
-      '#type' => 'checkbox',
1568
-      '#title' => t('Delete this message for all users?'),
1569
-      '#description' => t('Tick the box to delete the message for all users.'),
1570
-      '#default_value' => FALSE,
1566
+        '#type' => 'checkbox',
1567
+        '#title' => t('Delete this message for all users?'),
1568
+        '#description' => t('Tick the box to delete the message for all users.'),
1569
+        '#default_value' => FALSE,
1571 1570
     );
1572
-  }
1573
-  return confirm_form($form,
1571
+    }
1572
+    return confirm_form($form,
1574 1573
     t('Are you sure you want to delete this message?'),
1575 1574
     isset($_GET['destination']) ? $_GET['destination'] : 'messages/view/'. $message['thread_id'],
1576 1575
     t('This action cannot be undone.'),
1577 1576
     t('Delete'),
1578 1577
     t('Cancel')
1579
-  );
1578
+    );
1580 1579
 }
1581 1580
 
1582 1581
 function privatemsg_delete_submit($form, &$form_state) {
1583
-  global $user;
1584
-  $account = drupal_clone($user);
1582
+    global $user;
1583
+    $account = drupal_clone($user);
1585 1584
 
1586
-  if ($form_state['values']['confirm']) {
1585
+    if ($form_state['values']['confirm']) {
1587 1586
     if (isset($form_state['values']['delete_options']) && $form_state['values']['delete_options']) {
1588
-      privatemsg_message_change_delete($form_state['values']['pmid'], 1);
1589
-      drupal_set_message(t('Message has been deleted for all users.'));
1587
+        privatemsg_message_change_delete($form_state['values']['pmid'], 1);
1588
+        drupal_set_message(t('Message has been deleted for all users.'));
1590 1589
     }
1591 1590
     else {
1592
-      privatemsg_message_change_delete($form_state['values']['pmid'], 1, $account);
1593
-      drupal_set_message(t('Message has been deleted.'));
1591
+        privatemsg_message_change_delete($form_state['values']['pmid'], 1, $account);
1592
+        drupal_set_message(t('Message has been deleted.'));
1594 1593
     }
1595
-  }
1596
-  $form_state['redirect'] = $form_state['values']['delete_destination'];
1594
+    }
1595
+    $form_state['redirect'] = $form_state['values']['delete_destination'];
1597 1596
 }
1598 1597
 
1599 1598
 /**
@@ -1610,18 +1609,18 @@  discard block
 block discarded – undo
1610 1609
  * @ingroup api
1611 1610
  */
1612 1611
 function privatemsg_message_change_delete($pmid, $delete, $account = NULL) {
1613
-  $delete_value = 0;
1614
-  if ($delete == TRUE) {
1612
+    $delete_value = 0;
1613
+    if ($delete == TRUE) {
1615 1614
     $delete_value = time();
1616
-  }
1615
+    }
1617 1616
 
1618
-  if ($account) {
1617
+    if ($account) {
1619 1618
     db_query('UPDATE {pm_index} SET deleted = %d WHERE mid = %d AND uid = %d', $delete_value, $pmid, $account->uid);
1620
-  }
1621
-  else {
1619
+    }
1620
+    else {
1622 1621
     // Mark deleted for all users.
1623 1622
     db_query('UPDATE {pm_index} SET deleted = %d WHERE mid = %d', $delete_value, $pmid);
1624
-  }
1623
+    }
1625 1624
 }
1626 1625
 
1627 1626
 /**
@@ -1664,35 +1663,35 @@  discard block
 block discarded – undo
1664 1663
  * @ingroup api
1665 1664
  */
1666 1665
 function privatemsg_new_thread($recipients, $subject, $body = NULL, $options = array()) {
1667
-  global $user;
1668
-  $author = drupal_clone($user);
1669
-
1670
-  $message = array();
1671
-  $message['subject'] = $subject;
1672
-  $message['body'] = $body;
1673
-  // Make sure that recipients are keyed by user id and are not added
1674
-  // multiple times.
1675
-  foreach ($recipients as $recipient) {
1666
+    global $user;
1667
+    $author = drupal_clone($user);
1668
+
1669
+    $message = array();
1670
+    $message['subject'] = $subject;
1671
+    $message['body'] = $body;
1672
+    // Make sure that recipients are keyed by user id and are not added
1673
+    // multiple times.
1674
+    foreach ($recipients as $recipient) {
1676 1675
     $message['recipients'][$recipient->uid] = $recipient;
1677
-  }
1676
+    }
1678 1677
 
1679
-  // Set custom options, if any.
1680
-  if (!empty($options)) {
1678
+    // Set custom options, if any.
1679
+    if (!empty($options)) {
1681 1680
     $message += $options;
1682
-  }
1683
-  // Apply defaults - this will not overwrite existing keys.
1684
-  $message += array(
1681
+    }
1682
+    // Apply defaults - this will not overwrite existing keys.
1683
+    $message += array(
1685 1684
     'author' => $author,
1686 1685
     'timestamp' => time(),
1687 1686
     'format' => filter_resolve_format(FILTER_FORMAT_DEFAULT),
1688
-  );
1687
+    );
1689 1688
 
1690
-  $validated = _privatemsg_validate_message($message);
1691
-  if ($validated['success']) {
1689
+    $validated = _privatemsg_validate_message($message);
1690
+    if ($validated['success']) {
1692 1691
     $validated['message'] = _privatemsg_send($message);
1693
-  }
1692
+    }
1694 1693
 
1695
-  return $validated;
1694
+    return $validated;
1696 1695
 }
1697 1696
 
1698 1697
 /**
@@ -1729,144 +1728,144 @@  discard block
 block discarded – undo
1729 1728
  * @ingroup api
1730 1729
  */
1731 1730
 function privatemsg_reply($thread_id, $body, $options = array()) {
1732
-  global $user;
1733
-  $author = drupal_clone($user);
1731
+    global $user;
1732
+    $author = drupal_clone($user);
1734 1733
 
1735
-  $message = array();
1736
-  $message['body'] = $body;
1734
+    $message = array();
1735
+    $message['body'] = $body;
1737 1736
 
1738
-  // set custom options, if any
1739
-  if (!empty($options)) {
1737
+    // set custom options, if any
1738
+    if (!empty($options)) {
1740 1739
     $message += $options;
1741
-  }
1742
-  // apply defaults
1743
-  $message += array(
1740
+    }
1741
+    // apply defaults
1742
+    $message += array(
1744 1743
     'author' => $author,
1745 1744
     'timestamp' => time(),
1746 1745
     'format' => filter_resolve_format(FILTER_FORMAT_DEFAULT),
1747
-  );
1746
+    );
1748 1747
 
1749
-  // We don't know the subject and the recipients, so we need to load them..
1750
-  // thread_id == mid on the first message of the thread
1751
-  $first_message = privatemsg_message_load($thread_id, $message['author']);
1752
-  if (!$first_message) {
1748
+    // We don't know the subject and the recipients, so we need to load them..
1749
+    // thread_id == mid on the first message of the thread
1750
+    $first_message = privatemsg_message_load($thread_id, $message['author']);
1751
+    if (!$first_message) {
1753 1752
     return array(t('Thread %thread_id not found, unable to answer', array('%thread_id' => $thread_id)));
1754
-  }
1753
+    }
1755 1754
 
1756
-  $message['thread_id'] = $thread_id;
1757
-  // Load participants.
1758
-  $message['recipients'] = _privatemsg_load_thread_participants($thread_id);
1759
-  // Remove author.
1760
-  if (isset($message['recipients'][$message['author']->uid]) && count($message['recipients']) > 1) {
1755
+    $message['thread_id'] = $thread_id;
1756
+    // Load participants.
1757
+    $message['recipients'] = _privatemsg_load_thread_participants($thread_id);
1758
+    // Remove author.
1759
+    if (isset($message['recipients'][$message['author']->uid]) && count($message['recipients']) > 1) {
1761 1760
     unset($message['recipients'][$message['author']->uid]);
1762
-  }
1763
-  $message['subject'] = $first_message['subject'];
1761
+    }
1762
+    $message['subject'] = $first_message['subject'];
1764 1763
 
1765
-  $validated = _privatemsg_validate_message($message);
1766
-  if ($validated['success']) {
1764
+    $validated = _privatemsg_validate_message($message);
1765
+    if ($validated['success']) {
1767 1766
     $validated['message'] = _privatemsg_send($message);
1768
-  }
1769
-  return $validated;
1767
+    }
1768
+    return $validated;
1770 1769
 }
1771 1770
 
1772 1771
 function _privatemsg_validate_message(&$message, $form = FALSE) {
1773
-  $messages = array('error' => array(), 'warning' => array());
1774
-  if (!privatemsg_user_access('write privatemsg', $message['author'])) {
1772
+    $messages = array('error' => array(), 'warning' => array());
1773
+    if (!privatemsg_user_access('write privatemsg', $message['author'])) {
1775 1774
     // no need to do further checks in this case...
1776 1775
     if ($form) {
1777
-      form_set_error('author', t('User @user is not allowed to write messages', array('@user' => $message['author']->name)));
1778
-      return array(
1776
+        form_set_error('author', t('User @user is not allowed to write messages', array('@user' => $message['author']->name)));
1777
+        return array(
1779 1778
         'success'  => FALSE,
1780 1779
         'messages'   => $messages,
1781
-      );
1780
+        );
1782 1781
     }
1783 1782
     else {
1784
-      $messages['error'][] = t('User @user is not allowed to write messages', array('@user' => $message['author']->name));
1785
-      return array(
1786
-         'success'  => FALSE,
1787
-         'messages'   => $messages,
1788
-      );
1783
+        $messages['error'][] = t('User @user is not allowed to write messages', array('@user' => $message['author']->name));
1784
+        return array(
1785
+            'success'  => FALSE,
1786
+            'messages'   => $messages,
1787
+        );
1788
+    }
1789 1789
     }
1790
-  }
1791 1790
 
1792
-  // Prevent subjects which only consist of a space as these can not be clicked.
1793
-  $message['subject'] = trim($message['subject']);
1794
-  if (empty($message['subject'])) {
1791
+    // Prevent subjects which only consist of a space as these can not be clicked.
1792
+    $message['subject'] = trim($message['subject']);
1793
+    if (empty($message['subject'])) {
1795 1794
     if ($form) {
1796
-      form_set_error('subject', t('Disallowed to send a message without subject'));
1795
+        form_set_error('subject', t('Disallowed to send a message without subject'));
1797 1796
     }
1798 1797
     else {
1799
-      $messages['error'][] = t('Disallowed to send a message without subject');
1798
+        $messages['error'][] = t('Disallowed to send a message without subject');
1799
+    }
1800 1800
     }
1801
-  }
1802 1801
 
1803
-  // Don't allow replies without a body.
1804
-  if (!empty($message['thread_id']) && ($message['body'] === NULL || $message['body'] === '') ) {
1802
+    // Don't allow replies without a body.
1803
+    if (!empty($message['thread_id']) && ($message['body'] === NULL || $message['body'] === '') ) {
1805 1804
     if ($form) {
1806
-      form_set_error('body', t('Disallowed to send reply without a message.'));
1805
+        form_set_error('body', t('Disallowed to send reply without a message.'));
1807 1806
     }
1808 1807
     else {
1809
-      $messages['error'][] = t('Disallowed to send reply without a message.');
1808
+        $messages['error'][] = t('Disallowed to send reply without a message.');
1809
+    }
1810 1810
     }
1811
-  }
1812
-  // Check if an allowed format is used. global $user needs to be changed since
1813
-  // it is not possible to do the check for a specific user.
1814
-  global $user;
1815
-  $original_user = drupal_clone($user);
1816
-  session_save_session(FALSE);
1817
-  $user = $message['author'];
1811
+    // Check if an allowed format is used. global $user needs to be changed since
1812
+    // it is not possible to do the check for a specific user.
1813
+    global $user;
1814
+    $original_user = drupal_clone($user);
1815
+    session_save_session(FALSE);
1816
+    $user = $message['author'];
1818 1817
 
1819
-  if (!filter_access($message['format'])) {
1818
+    if (!filter_access($message['format'])) {
1820 1819
     if ($form) {
1821
-      form_set_error('format', t('You are not allowed to use the specified input format.'));
1820
+        form_set_error('format', t('You are not allowed to use the specified input format.'));
1822 1821
     }
1823 1822
     else {
1824
-      $messages['error'][] = t('User @user is not allowed to use the specified input format.', array('@user' => $message['author']->name));
1823
+        $messages['error'][] = t('User @user is not allowed to use the specified input format.', array('@user' => $message['author']->name));
1824
+    }
1825 1825
     }
1826
-  }
1827 1826
 
1828
-  $user = $original_user;
1829
-  session_save_session(TRUE);
1827
+    $user = $original_user;
1828
+    session_save_session(TRUE);
1830 1829
 
1831
-  if (empty($message['recipients']) || !is_array($message['recipients'])) {
1830
+    if (empty($message['recipients']) || !is_array($message['recipients'])) {
1832 1831
     if ($form) {
1833
-      form_set_error('to', t('Disallowed to send a message without at least one valid recipient'));
1832
+        form_set_error('to', t('Disallowed to send a message without at least one valid recipient'));
1834 1833
     }
1835 1834
     else {
1836
-      $messages['error'][] = t('Disallowed to send a message without at least one valid recipient');
1835
+        $messages['error'][] = t('Disallowed to send a message without at least one valid recipient');
1836
+    }
1837 1837
     }
1838
-  }
1839 1838
 
1840
-  if (!empty($message['recipients']) && is_array($message['recipients'])) {
1839
+    if (!empty($message['recipients']) && is_array($message['recipients'])) {
1841 1840
     foreach (module_invoke_all('privatemsg_block_message', $message['author'], $message['recipients']) as $blocked) {
1842
-      unset($message['recipients'][$blocked['uid']]);
1843
-      if ($form) {
1841
+        unset($message['recipients'][$blocked['uid']]);
1842
+        if ($form) {
1844 1843
         drupal_set_message($blocked['message'], 'warning');
1845
-      }
1846
-      else {
1844
+        }
1845
+        else {
1847 1846
         $messages['warning'][] = $blocked['message'];
1848
-      }
1847
+        }
1848
+    }
1849 1849
     }
1850
-  }
1851 1850
 
1852
-  // Check again, give another error message if all recipients are blocked
1853
-  if (empty($message['recipients'])) {
1851
+    // Check again, give another error message if all recipients are blocked
1852
+    if (empty($message['recipients'])) {
1854 1853
     if ($form) {
1855
-      form_set_error('to', t('Disallowed to send message because all recipients are blocked'));
1854
+        form_set_error('to', t('Disallowed to send message because all recipients are blocked'));
1856 1855
     }
1857 1856
     else {
1858
-      $messages['error'][] = t('Disallowed to send message because all recipients are blocked');
1857
+        $messages['error'][] = t('Disallowed to send message because all recipients are blocked');
1858
+    }
1859 1859
     }
1860
-  }
1861 1860
 
1862
-  $messages = array_merge_recursive(module_invoke_all('privatemsg_message_validate', $message, $form), $messages);
1861
+    $messages = array_merge_recursive(module_invoke_all('privatemsg_message_validate', $message, $form), $messages);
1863 1862
 
1864
-  // Check if there are errors in $messages or if $form is TRUE, there are form errors.
1865
-  $success = empty($messages['error']) || ($form && count((array)form_get_errors()) > 0);
1866
-  return array(
1863
+    // Check if there are errors in $messages or if $form is TRUE, there are form errors.
1864
+    $success = empty($messages['error']) || ($form && count((array)form_get_errors()) > 0);
1865
+    return array(
1867 1866
     'success'  => $success,
1868 1867
     'messages'   => $messages,
1869
-  );
1868
+    );
1870 1869
 }
1871 1870
 
1872 1871
 /**
@@ -1882,61 +1881,61 @@  discard block
 block discarded – undo
1882 1881
  */
1883 1882
 function _privatemsg_send($message) {
1884 1883
 
1885
-  drupal_alter('privatemsg_message_presave', $message);
1884
+    drupal_alter('privatemsg_message_presave', $message);
1886 1885
 
1887
-  $index_sql = "INSERT INTO {pm_index} (mid, thread_id, uid, is_new, deleted) VALUES (%d, %d, %d, %d, 0)";
1888
-  if (isset($message['read_all']) && $message['read_all']) {
1886
+    $index_sql = "INSERT INTO {pm_index} (mid, thread_id, uid, is_new, deleted) VALUES (%d, %d, %d, %d, 0)";
1887
+    if (isset($message['read_all']) && $message['read_all']) {
1889 1888
     // The message was sent in read all mode, add the author as recipient to all
1890 1889
     // existing messages.
1891 1890
     $query_messages = _privatemsg_assemble_query('messages', array($message['thread_id']), NULL);
1892 1891
     $conversation = db_query($query_messages['query']);
1893 1892
     while ($result = db_fetch_array($conversation)) {
1894
-      if (!db_query($index_sql, $result['mid'], $message['thread_id'], $message['author']->uid, 0)) {
1893
+        if (!db_query($index_sql, $result['mid'], $message['thread_id'], $message['author']->uid, 0)) {
1895 1894
         return FALSE;
1896
-      }
1897
-    }
1898
-  }
1899
-
1900
-  // 1) Save the message body first.
1901
-  $args = array();
1902
-  $args[] = $message['subject'];
1903
-  $args[] = $message['author']->uid;
1904
-  $args[] = $message['body'];
1905
-  $args[] = $message['format'];
1906
-  $args[] = $message['timestamp'];
1907
-  $message_sql = "INSERT INTO {pm_message} (subject, author, body, format, timestamp) VALUES ('%s', %d, '%s', %d, %d)";
1908
-  db_query($message_sql, $args);
1909
-  $mid = db_last_insert_id('pm_message', 'mid');
1910
-  $message['mid'] = $mid;
1911
-
1912
-  // Thread ID is the same as the mid if it's the first message in the thread.
1913
-  if (!isset($message['thread_id'])) {
1895
+        }
1896
+    }
1897
+    }
1898
+
1899
+    // 1) Save the message body first.
1900
+    $args = array();
1901
+    $args[] = $message['subject'];
1902
+    $args[] = $message['author']->uid;
1903
+    $args[] = $message['body'];
1904
+    $args[] = $message['format'];
1905
+    $args[] = $message['timestamp'];
1906
+    $message_sql = "INSERT INTO {pm_message} (subject, author, body, format, timestamp) VALUES ('%s', %d, '%s', %d, %d)";
1907
+    db_query($message_sql, $args);
1908
+    $mid = db_last_insert_id('pm_message', 'mid');
1909
+    $message['mid'] = $mid;
1910
+
1911
+    // Thread ID is the same as the mid if it's the first message in the thread.
1912
+    if (!isset($message['thread_id'])) {
1914 1913
     $message['thread_id'] = $mid;
1915
-  }
1914
+    }
1916 1915
 
1917
-  // 2) Save message to recipients.
1918
-  // Each recipient gets a record in the pm_index table.
1919
-  foreach ($message['recipients'] as $recipient) {
1916
+    // 2) Save message to recipients.
1917
+    // Each recipient gets a record in the pm_index table.
1918
+    foreach ($message['recipients'] as $recipient) {
1920 1919
     if (!db_query($index_sql, $mid, $message['thread_id'], $recipient->uid, 1) ) {
1921
-      // We assume if one insert failed then the rest may fail too against the
1922
-      // same table.
1923
-      return FALSE;
1920
+        // We assume if one insert failed then the rest may fail too against the
1921
+        // same table.
1922
+        return FALSE;
1923
+    }
1924 1924
     }
1925
-  }
1926 1925
 
1927
-  // When author is also the recipient, we want to set message to UNREAD.
1928
-  // All other times the message is set to READ.
1929
-  $is_new = isset($message['recipients'][$message['author']->uid]) ? 1 : 0;
1926
+    // When author is also the recipient, we want to set message to UNREAD.
1927
+    // All other times the message is set to READ.
1928
+    $is_new = isset($message['recipients'][$message['author']->uid]) ? 1 : 0;
1930 1929
 
1931
-  // Also add a record for the author to the pm_index table.
1932
-  if (!db_query($index_sql, $mid, $message['thread_id'], $message['author']->uid, $is_new)) {
1930
+    // Also add a record for the author to the pm_index table.
1931
+    if (!db_query($index_sql, $mid, $message['thread_id'], $message['author']->uid, $is_new)) {
1933 1932
     return FALSE;
1934
-  }
1933
+    }
1935 1934
 
1936
-  module_invoke_all('privatemsg_message_insert', $message);
1935
+    module_invoke_all('privatemsg_message_insert', $message);
1937 1936
 
1938
-  // If we reached here that means we were successful at writing all messages to db.
1939
-  return $message;
1937
+    // If we reached here that means we were successful at writing all messages to db.
1938
+    return $message;
1940 1939
 }
1941 1940
 
1942 1941
 /**
@@ -1956,37 +1955,37 @@  discard block
 block discarded – undo
1956 1955
  * @ingroup api
1957 1956
  */
1958 1957
 function privatemsg_get_link($recipients, $account = array(), $subject = NULL) {
1959
-  if ($account == NULL) {
1958
+    if ($account == NULL) {
1960 1959
     global $user;
1961 1960
     $account = $user;
1962
-  }
1961
+    }
1963 1962
 
1964
-  if (!is_array($recipients)) {
1963
+    if (!is_array($recipients)) {
1965 1964
     $recipients = array($recipients);
1966
-  }
1965
+    }
1967 1966
 
1968
-  if (!privatemsg_user_access('write privatemsg', $account) || $account->uid == 0) {
1967
+    if (!privatemsg_user_access('write privatemsg', $account) || $account->uid == 0) {
1969 1968
     return FALSE;
1970
-  }
1969
+    }
1971 1970
 
1972
-  $validated = array();
1973
-  foreach ($recipients as $recipient) {
1971
+    $validated = array();
1972
+    foreach ($recipients as $recipient) {
1974 1973
     if (!privatemsg_user_access('read privatemsg', $recipient)) {
1975
-      continue;
1974
+        continue;
1976 1975
     }
1977 1976
     if (count(module_invoke_all('privatemsg_block_message', $account, array($recipient->uid => $recipient))) > 0) {
1978
-      continue;
1977
+        continue;
1979 1978
     }
1980 1979
     $validated[] = $recipient->uid;
1981
-  }
1982
-  if (empty($validated)) {
1980
+    }
1981
+    if (empty($validated)) {
1983 1982
     return FALSE;
1984
-  }
1985
-  $url = 'messages/new/'. implode(',', $validated);
1986
-  if (!is_null($subject)) {
1983
+    }
1984
+    $url = 'messages/new/'. implode(',', $validated);
1985
+    if (!is_null($subject)) {
1987 1986
     $url .= '/'. $subject;
1988
-  }
1989
-  return $url;
1987
+    }
1988
+    return $url;
1990 1989
 }
1991 1990
 
1992 1991
 /**
@@ -2001,8 +2000,8 @@  discard block
 block discarded – undo
2001 2000
  * @ingroup api
2002 2001
  */
2003 2002
 function privatemsg_message_load($pmid, $account = NULL) {
2004
-  $messages = privatemsg_message_load_multiple(array($pmid), $account);
2005
-  return current($messages);
2003
+    $messages = privatemsg_message_load_multiple(array($pmid), $account);
2004
+    return current($messages);
2006 2005
 }
2007 2006
 
2008 2007
 /**
@@ -2017,27 +2016,27 @@  discard block
 block discarded – undo
2017 2016
  * @ingroup api
2018 2017
  */
2019 2018
 function privatemsg_message_load_multiple($pmids, $account = NULL) {
2020
-  // Avoid SQL error that would happen with an empty pm.mid IN () clause.
2021
-  if (empty($pmids)) {
2019
+    // Avoid SQL error that would happen with an empty pm.mid IN () clause.
2020
+    if (empty($pmids)) {
2022 2021
     return array();
2023
-  }
2022
+    }
2024 2023
 
2025
-  $query = _privatemsg_assemble_query('load', $pmids, $account);
2026
-  $result = db_query($query['query']);
2027
-  $messages = array();
2028
-  while ($message = db_fetch_array($result)) {
2024
+    $query = _privatemsg_assemble_query('load', $pmids, $account);
2025
+    $result = db_query($query['query']);
2026
+    $messages = array();
2027
+    while ($message = db_fetch_array($result)) {
2029 2028
     // Load author of message.
2030 2029
     if (!($message['author'] = user_load($message['author']))) {
2031
-      // If user does not exist, load anonymous user.
2032
-      $message['author'] = user_load(array('uid' => 0));
2030
+        // If user does not exist, load anonymous user.
2031
+        $message['author'] = user_load(array('uid' => 0));
2033 2032
     }
2034 2033
     $returned = module_invoke_all('privatemsg_message_load', $message);
2035 2034
     if (!empty($returned)) {
2036
-      $message = array_merge_recursive($returned, $message);
2035
+        $message = array_merge_recursive($returned, $message);
2037 2036
     }
2038 2037
     $messages[$message['mid']] = $message;
2039
-  }
2040
-  return $messages;
2038
+    }
2039
+    return $messages;
2041 2040
 }
2042 2041
 
2043 2042
 /**
@@ -2056,26 +2055,26 @@  discard block
 block discarded – undo
2056 2055
  */
2057 2056
 function _privatemsg_assemble_query($query) {
2058 2057
 
2059
-  // Modules will be allowed to choose the prefix for the querybuilder, but if there is not one supplied, 'privatemsg' will be taken by default.
2060
-  if (is_array($query)) {
2058
+    // Modules will be allowed to choose the prefix for the querybuilder, but if there is not one supplied, 'privatemsg' will be taken by default.
2059
+    if (is_array($query)) {
2061 2060
     $query_id = $query[0];
2062 2061
     $query_group = $query[1];
2063
-  }
2064
-  else {
2062
+    }
2063
+    else {
2065 2064
     $query_id = $query;
2066 2065
     $query_group = 'privatemsg';
2067
-  }
2068
-
2069
-  $SELECT = array();
2070
-  $INNER_JOIN = array();
2071
-  $WHERE = array();
2072
-  $GROUP_BY = array();
2073
-  $HAVING   = array();
2074
-  $ORDER_BY = array();
2075
-  $QUERY_ARGS = array('select' => array(), 'where' => array(), 'join' => array(), 'having' => array());
2076
-  $primary_table = '';
2077
-
2078
-  $fragments = array(
2066
+    }
2067
+
2068
+    $SELECT = array();
2069
+    $INNER_JOIN = array();
2070
+    $WHERE = array();
2071
+    $GROUP_BY = array();
2072
+    $HAVING   = array();
2073
+    $ORDER_BY = array();
2074
+    $QUERY_ARGS = array('select' => array(), 'where' => array(), 'join' => array(), 'having' => array());
2075
+    $primary_table = '';
2076
+
2077
+    $fragments = array(
2079 2078
     'select'      => $SELECT,
2080 2079
     'inner_join'  => $INNER_JOIN,
2081 2080
     'where'       => $WHERE,
@@ -2084,52 +2083,52 @@  discard block
 block discarded – undo
2084 2083
     'order_by'    => $ORDER_BY,
2085 2084
     'query_args'  => $QUERY_ARGS,
2086 2085
     'primary_table'  => $primary_table,
2087
-  );
2088
-
2089
-  /**
2090
-   * Begin: dynamic arguments
2091
-   */
2092
-  $args = func_get_args();
2093
-  unset($args[0]);
2094
-  // we do the merge because we call call_user_func_array and not drupal_alter
2095
-  // this is necessary because otherwise we would not be able to use $args correctly (otherwise it doesnt unfold)
2096
-  $alterargs = array(&$fragments);
2097
-  $query_function = $query_group .'_sql_'. $query_id;
2098
-  if (!empty($args)) {
2086
+    );
2087
+
2088
+    /**
2089
+     * Begin: dynamic arguments
2090
+     */
2091
+    $args = func_get_args();
2092
+    unset($args[0]);
2093
+    // we do the merge because we call call_user_func_array and not drupal_alter
2094
+    // this is necessary because otherwise we would not be able to use $args correctly (otherwise it doesnt unfold)
2095
+    $alterargs = array(&$fragments);
2096
+    $query_function = $query_group .'_sql_'. $query_id;
2097
+    if (!empty($args)) {
2099 2098
     $alterargs = array_merge($alterargs, $args);
2100
-  }
2101
-  /**
2102
-   * END: Dynamic arguments
2103
-   */
2104
-  if (!function_exists($query_function)) {
2099
+    }
2100
+    /**
2101
+     * END: Dynamic arguments
2102
+     */
2103
+    if (!function_exists($query_function)) {
2105 2104
     drupal_set_message(t('Query function %function does not exist', array('%function' => $query_function)), 'error');
2106 2105
     return FALSE;
2107
-  }
2108
-  call_user_func_array($query_function, $alterargs);
2109
-
2110
-  array_unshift($alterargs, $query_function);
2111
-  call_user_func_array('drupal_alter', $alterargs);
2112
-
2113
-  $SELECT = $fragments['select'];
2114
-  $INNER_JOIN = $fragments['inner_join'];
2115
-  $WHERE = $fragments['where'];
2116
-  $GROUP_BY = $fragments['group_by'];
2117
-  $HAVING   = $fragments['having'];
2118
-  $ORDER_BY = $fragments['order_by'];
2119
-  $QUERY_ARGS = $fragments['query_args'];
2120
-  $primary_table = $fragments['primary_table'];
2121
-
2122
-  // pgsql has a case sensitive LIKE - replace it with ILIKE. see http://drupal.org/node/462982
2123
-  if ($GLOBALS['db_type'] == 'pgsql') {
2106
+    }
2107
+    call_user_func_array($query_function, $alterargs);
2108
+
2109
+    array_unshift($alterargs, $query_function);
2110
+    call_user_func_array('drupal_alter', $alterargs);
2111
+
2112
+    $SELECT = $fragments['select'];
2113
+    $INNER_JOIN = $fragments['inner_join'];
2114
+    $WHERE = $fragments['where'];
2115
+    $GROUP_BY = $fragments['group_by'];
2116
+    $HAVING   = $fragments['having'];
2117
+    $ORDER_BY = $fragments['order_by'];
2118
+    $QUERY_ARGS = $fragments['query_args'];
2119
+    $primary_table = $fragments['primary_table'];
2120
+
2121
+    // pgsql has a case sensitive LIKE - replace it with ILIKE. see http://drupal.org/node/462982
2122
+    if ($GLOBALS['db_type'] == 'pgsql') {
2124 2123
     $WHERE = str_replace('LIKE', 'ILIKE', $WHERE);
2125
-  }
2124
+    }
2126 2125
 
2127
-  if (empty($primary_table)) {
2126
+    if (empty($primary_table)) {
2128 2127
     $primary_table = '{privatemsg} pm';
2129
-  }
2128
+    }
2130 2129
 
2131
-  // Perform the whole query assembly only if we have something to select.
2132
-  if (!empty($SELECT)) {
2130
+    // Perform the whole query assembly only if we have something to select.
2131
+    if (!empty($SELECT)) {
2133 2132
     $str_select = implode(", ", $SELECT);
2134 2133
     $query = "SELECT {$str_select} FROM ". $primary_table;
2135 2134
 
@@ -2137,51 +2136,51 @@  discard block
 block discarded – undo
2137 2136
     // In most cases,  "COUNT(*)" is enough to get the count query, but in queries involving a GROUP BY, we want a count of the number of groups we have, not the count of elements inside each group.
2138 2137
     // So we test if there is GROUP BY and if there is, count the number of distinct groups. If not, we go the normal wal and do a plain COUNT(*).
2139 2138
     if (!empty($GROUP_BY)) {
2140
-      // PostgreSQL does not support COUNT(sometextfield, someintfield), so I'm only using the first one
2141
-      // Works fine for thread_id/list but may generate an error when a more complex GROUP BY is used.
2142
-      $str_group_by_count = current($GROUP_BY);
2143
-      $count = "SELECT COUNT(DISTINCT {$str_group_by_count}) FROM ". $primary_table;
2139
+        // PostgreSQL does not support COUNT(sometextfield, someintfield), so I'm only using the first one
2140
+        // Works fine for thread_id/list but may generate an error when a more complex GROUP BY is used.
2141
+        $str_group_by_count = current($GROUP_BY);
2142
+        $count = "SELECT COUNT(DISTINCT {$str_group_by_count}) FROM ". $primary_table;
2144 2143
     }
2145 2144
     else {
2146
-      $count = "SELECT COUNT(*) FROM ". $primary_table;
2145
+        $count = "SELECT COUNT(*) FROM ". $primary_table;
2147 2146
     }
2148 2147
 
2149 2148
     if (!empty($INNER_JOIN)) {
2150
-      $str_inner_join = implode(' ', $INNER_JOIN);
2151
-      $query .= " {$str_inner_join}";
2152
-      $count .= " {$str_inner_join}";
2149
+        $str_inner_join = implode(' ', $INNER_JOIN);
2150
+        $query .= " {$str_inner_join}";
2151
+        $count .= " {$str_inner_join}";
2153 2152
     }
2154 2153
     if (!empty($WHERE)) {
2155
-      $str_where = '('. implode(') AND (', $WHERE) .')';
2156
-      $query .= " WHERE {$str_where}";
2157
-      $count .= " WHERE {$str_where}";
2154
+        $str_where = '('. implode(') AND (', $WHERE) .')';
2155
+        $query .= " WHERE {$str_where}";
2156
+        $count .= " WHERE {$str_where}";
2158 2157
     }
2159 2158
     if (!empty($GROUP_BY)) {
2160
-      $str_group_by = ' GROUP BY '. implode(", ", $GROUP_BY) ;
2161
-      $query .= " {$str_group_by}";
2159
+        $str_group_by = ' GROUP BY '. implode(", ", $GROUP_BY) ;
2160
+        $query .= " {$str_group_by}";
2162 2161
     }
2163 2162
     if (!empty($HAVING)) {
2164
-      $str_having = '('. implode(') AND (', $HAVING) .')';
2165
-      $query .= " HAVING {$str_having}";
2166
-      // queries containing a HAVING break the count query on pgsql.
2167
-      // In this case, use the subquery method as outlined in http://drupal.org/node/303087#comment-1370752 .
2168
-      // The subquery method will work for all COUNT queries, but it is thought to be much slower, so we are only using it where other cross database approaches fail.
2169
-      $count = 'SELECT COUNT(*) FROM ('. $query .') as count';
2163
+        $str_having = '('. implode(') AND (', $HAVING) .')';
2164
+        $query .= " HAVING {$str_having}";
2165
+        // queries containing a HAVING break the count query on pgsql.
2166
+        // In this case, use the subquery method as outlined in http://drupal.org/node/303087#comment-1370752 .
2167
+        // The subquery method will work for all COUNT queries, but it is thought to be much slower, so we are only using it where other cross database approaches fail.
2168
+        $count = 'SELECT COUNT(*) FROM ('. $query .') as count';
2170 2169
     }
2171 2170
     if (!empty($ORDER_BY)) {
2172
-      $str_order_by = ' ORDER BY '. implode(", ", $ORDER_BY) ;
2173
-      $query .= " {$str_order_by}";
2171
+        $str_order_by = ' ORDER BY '. implode(", ", $ORDER_BY) ;
2172
+        $query .= " {$str_order_by}";
2174 2173
     }
2175 2174
     $QUERY_ARGS = array_merge($QUERY_ARGS['select'], $QUERY_ARGS['join'], $QUERY_ARGS['where'], $QUERY_ARGS['having']);
2176 2175
     if (!empty($QUERY_ARGS)) {
2177
-      _db_query_callback($QUERY_ARGS, TRUE);
2178
-      $query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $query);
2179
-      _db_query_callback($QUERY_ARGS, TRUE);
2180
-      $count = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $count);
2176
+        _db_query_callback($QUERY_ARGS, TRUE);
2177
+        $query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $query);
2178
+        _db_query_callback($QUERY_ARGS, TRUE);
2179
+        $count = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $count);
2181 2180
     }
2182 2181
     return array('query' => $query, 'count' => $count);
2183
-  }
2184
-  return FALSE;
2182
+    }
2183
+    return FALSE;
2185 2184
 }
2186 2185
 
2187 2186
 /**
@@ -2198,44 +2197,44 @@  discard block
 block discarded – undo
2198 2197
  *   The FAPI definitions for the thread action form.
2199 2198
  */
2200 2199
 function _privatemsg_action_form() {
2201
-  $form = array(
2202
-      '#type'        => 'fieldset',
2203
-      '#title'       => t('Actions'),
2204
-      '#prefix'      => '<div class="container-inline">',
2205
-      '#suffix'      => '</div>',
2206
-      '#collapsible' => TRUE,
2207
-      '#collapsed'   => FALSE,
2208
-      '#weight'      => 15,
2209
-  );
2210
-  if (privatemsg_user_access('delete privatemsg')) {
2200
+    $form = array(
2201
+        '#type'        => 'fieldset',
2202
+        '#title'       => t('Actions'),
2203
+        '#prefix'      => '<div class="container-inline">',
2204
+        '#suffix'      => '</div>',
2205
+        '#collapsible' => TRUE,
2206
+        '#collapsed'   => FALSE,
2207
+        '#weight'      => 15,
2208
+    );
2209
+    if (privatemsg_user_access('delete privatemsg')) {
2211 2210
     $form['delete'] = array(
2212 2211
         '#type'   => 'submit',
2213 2212
         '#value'  => t('Delete'),
2214 2213
     );
2215
-  }
2216
-  // Display all operations which have a label.
2217
-  $options = array(0 => t('More actions...'));
2218
-  foreach (module_invoke_all('privatemsg_thread_operations') as $operation => $array) {
2214
+    }
2215
+    // Display all operations which have a label.
2216
+    $options = array(0 => t('More actions...'));
2217
+    foreach (module_invoke_all('privatemsg_thread_operations') as $operation => $array) {
2219 2218
     if (isset($array['label'])) {
2220
-      $options[$operation] = $array['label'];
2221
-    }
2222
-  }
2223
-  $form['operation'] = array(
2224
-      '#type'          => 'select',
2225
-      '#options'       => $options,
2226
-      '#default_value' => 0,
2227
-  );
2228
-  $form['submit'] = array(
2229
-      '#prefix'     => '<div class="privatemsg-op-button">',
2230
-      '#suffix'    => '</div>',
2231
-      '#type'       => 'submit',
2232
-      '#value'      => t('Execute'),
2233
-      '#submit'     => array('privatemsg_list_submit'),
2234
-      '#attributes' => array('class' => 'privatemsg-action-button'),
2235
-  );
2236
-  // JS for hiding the execute button.
2237
-  drupal_add_js(drupal_get_path('module', 'privatemsg') .'/privatemsg-list.js');
2238
-  return $form;
2219
+        $options[$operation] = $array['label'];
2220
+    }
2221
+    }
2222
+    $form['operation'] = array(
2223
+        '#type'          => 'select',
2224
+        '#options'       => $options,
2225
+        '#default_value' => 0,
2226
+    );
2227
+    $form['submit'] = array(
2228
+        '#prefix'     => '<div class="privatemsg-op-button">',
2229
+        '#suffix'    => '</div>',
2230
+        '#type'       => 'submit',
2231
+        '#value'      => t('Execute'),
2232
+        '#submit'     => array('privatemsg_list_submit'),
2233
+        '#attributes' => array('class' => 'privatemsg-action-button'),
2234
+    );
2235
+    // JS for hiding the execute button.
2236
+    drupal_add_js(drupal_get_path('module', 'privatemsg') .'/privatemsg-list.js');
2237
+    return $form;
2239 2238
 }
2240 2239
 
2241 2240
 /**
@@ -2250,23 +2249,23 @@  discard block
 block discarded – undo
2250 2249
  *   current user.
2251 2250
  */
2252 2251
 function privatemsg_thread_change_status($threads, $status, $account = NULL) {
2253
-  if (!is_array($threads)) {
2252
+    if (!is_array($threads)) {
2254 2253
     $threads = array($threads);
2255
-  }
2256
-  if (empty($account)) {
2254
+    }
2255
+    if (empty($account)) {
2257 2256
     global $user;
2258 2257
     $account = drupal_clone($user);
2259
-  }
2260
-  // Merge status and uid with the threads list. array_merge() will not overwrite/ignore thread_id 1.
2261
-  $params = array_merge(array($status, $account->uid), $threads);
2262
-  db_query('UPDATE {pm_index} SET is_new = %d WHERE uid = %d AND thread_id IN ('. db_placeholders($threads) .')', $params);
2258
+    }
2259
+    // Merge status and uid with the threads list. array_merge() will not overwrite/ignore thread_id 1.
2260
+    $params = array_merge(array($status, $account->uid), $threads);
2261
+    db_query('UPDATE {pm_index} SET is_new = %d WHERE uid = %d AND thread_id IN ('. db_placeholders($threads) .')', $params);
2263 2262
 
2264
-  if ($status == PRIVATEMSG_UNREAD) {
2263
+    if ($status == PRIVATEMSG_UNREAD) {
2265 2264
     drupal_set_message(format_plural(count($threads), 'Marked 1 thread as unread.', 'Marked @count threads as unread.'));
2266
-  }
2267
-  else {
2265
+    }
2266
+    else {
2268 2267
     drupal_set_message(format_plural(count($threads), 'Marked 1 thread as read.', 'Marked @count threads as read.'));
2269
-  }
2268
+    }
2270 2269
 }
2271 2270
 /**
2272 2271
  * Returns a table header definition based on the submitted keys.
@@ -2282,25 +2281,25 @@  discard block
 block discarded – undo
2282 2281
  *   Array with header defintions for tablesort_sql and theme('table').
2283 2282
  */
2284 2283
 function _privatemsg_list_headers($has_posts, $keys) {
2285
-  $select_header = $has_posts ? theme('table_select_header_cell') : '';
2286
-  $select_header['#weight'] = -50;
2284
+    $select_header = $has_posts ? theme('table_select_header_cell') : '';
2285
+    $select_header['#weight'] = -50;
2287 2286
 
2288
-  // theme() doesn't include the theme file for patterns, we need to do it manually.
2289
-  include_once drupal_get_path('module', 'privatemsg') .'/privatemsg.theme.inc';
2287
+    // theme() doesn't include the theme file for patterns, we need to do it manually.
2288
+    include_once drupal_get_path('module', 'privatemsg') .'/privatemsg.theme.inc';
2290 2289
 
2291
-  $header = array($select_header);
2292
-  foreach ($keys as $key) {
2290
+    $header = array($select_header);
2291
+    foreach ($keys as $key) {
2293 2292
     // First, try to load a specific theme for that header, if not present, use the default.
2294 2293
     if ($return = theme(array('privatemsg_list_header__'. $key, 'privatemsg_list_header'))) {
2295
-      // The default theme returns nothing, only store the value if we have something.
2296
-      $header[$key] = $return;
2294
+        // The default theme returns nothing, only store the value if we have something.
2295
+        $header[$key] = $return;
2296
+    }
2297 2297
     }
2298
-  }
2299
-  if (count($header) == 1) {
2298
+    if (count($header) == 1) {
2300 2299
     // No header definition returned, fallback to the default.
2301 2300
     $header += _privatemsg_list_headers_fallback($keys);
2302
-  }
2303
-  return $header;
2301
+    }
2302
+    return $header;
2304 2303
 }
2305 2304
 
2306 2305
 /**
@@ -2310,15 +2309,15 @@  discard block
 block discarded – undo
2310 2309
  *   Array with the correct headers.
2311 2310
  */
2312 2311
 function _privatemsg_list_headers_fallback($keys) {
2313
-  $header = array();
2314
-  foreach ($keys as $key) {
2312
+    $header = array();
2313
+    foreach ($keys as $key) {
2315 2314
     $theme_function = 'phptemplate_privatemsg_list_header__' . $key;
2316 2315
     if (function_exists($theme_function)) {
2317
-      $header[$key] = $theme_function();
2316
+        $header[$key] = $theme_function();
2317
+    }
2318 2318
     }
2319
-  }
2320 2319
 
2321
-  return $header;
2320
+    return $header;
2322 2321
 }
2323 2322
 
2324 2323
 /**
@@ -2332,23 +2331,23 @@  discard block
 block discarded – undo
2332 2331
  *   Row definition for use with theme('table')
2333 2332
  */
2334 2333
 function _privatemsg_list_thread($thread) {
2335
-  $row = array('data' => array());
2334
+    $row = array('data' => array());
2336 2335
 
2337
-  if (!empty($thread['is_new'])) {
2336
+    if (!empty($thread['is_new'])) {
2338 2337
     // Set the css class in the tr tag.
2339 2338
     $row['class'] = 'privatemsg-unread';
2340
-  }
2341
-  foreach ($thread as $key => $data) {
2339
+    }
2340
+    foreach ($thread as $key => $data) {
2342 2341
     // First, try to load a specific theme for that field, if not present, use the default.
2343 2342
     if ($return = theme(array('privatemsg_list_field__'. $key, 'privatemsg_list_field'), $thread)) {
2344
-      // The default theme returns nothing, only store the value if we have something.
2345
-      $row['data'][$key] = $return;
2343
+        // The default theme returns nothing, only store the value if we have something.
2344
+        $row['data'][$key] = $return;
2345
+    }
2346 2346
     }
2347
-  }
2348
-  if (empty($row['data'])) {
2347
+    if (empty($row['data'])) {
2349 2348
     $row['data'] = _privatemsg_list_thread_fallback($thread);
2350
-  }
2351
-  return $row;
2349
+    }
2350
+    return $row;
2352 2351
 }
2353 2352
 
2354 2353
 /**
@@ -2358,15 +2357,15 @@  discard block
 block discarded – undo
2358 2357
  *   Array with row data.
2359 2358
  */
2360 2359
 function _privatemsg_list_thread_fallback($thread) {
2361
-  $row_data = array();
2362
-  foreach ($thread as $key => $data) {
2360
+    $row_data = array();
2361
+    foreach ($thread as $key => $data) {
2363 2362
     $theme_function = 'phptemplate_privatemsg_list_field__' . $key;
2364 2363
     if (function_exists($theme_function)) {
2365
-      $row_data[$key] = $theme_function($thread);
2364
+        $row_data[$key] = $theme_function($thread);
2365
+    }
2366 2366
     }
2367
-  }
2368 2367
 
2369
-  return $row_data;
2368
+    return $row_data;
2370 2369
 }
2371 2370
 
2372 2371
 /**
@@ -2376,20 +2375,20 @@  discard block
 block discarded – undo
2376 2375
  * execute it.
2377 2376
  */
2378 2377
 function privatemsg_undo_action() {
2379
-  // Check if a undo callback for that user exists.
2380
-  if (isset($_SESSION['privatemsg']['undo callback']) && is_array($_SESSION['privatemsg']['undo callback'])) {
2378
+    // Check if a undo callback for that user exists.
2379
+    if (isset($_SESSION['privatemsg']['undo callback']) && is_array($_SESSION['privatemsg']['undo callback'])) {
2381 2380
     $undo = $_SESSION['privatemsg']['undo callback'];
2382 2381
     // If the defined undo callback exists, execute it
2383 2382
     if (isset($undo['function']) && isset($undo['args'])) {
2384
-      // Load the user object.
2385
-      if (isset($undo['args']['account']) && $undo['args']['account'] > 0) {
2383
+        // Load the user object.
2384
+        if (isset($undo['args']['account']) && $undo['args']['account'] > 0) {
2386 2385
         $undo['args']['account'] = user_load((int)$undo['args']['account']);
2387
-      }
2388
-      call_user_func_array($undo['function'], $undo['args']);
2386
+        }
2387
+        call_user_func_array($undo['function'], $undo['args']);
2389 2388
     }
2390 2389
     // Return back to the site defined by the destination GET param.
2391 2390
     drupal_goto();
2392
-  }
2391
+    }
2393 2392
 }
2394 2393
 
2395 2394
 /**
@@ -2399,29 +2398,29 @@  discard block
 block discarded – undo
2399 2398
  * based on node_admin_nodes_submit().
2400 2399
  */
2401 2400
 function privatemsg_list_submit($form, &$form_state) {
2402
-  // Load all available operation definitions.
2403
-  $operations = module_invoke_all('privatemsg_thread_operations');
2401
+    // Load all available operation definitions.
2402
+    $operations = module_invoke_all('privatemsg_thread_operations');
2404 2403
 
2405
-  // Default "default" operation, which won't do anything.
2406
-  $operation = array('callback' => 0);
2404
+    // Default "default" operation, which won't do anything.
2405
+    $operation = array('callback' => 0);
2407 2406
 
2408
-  // Check if a valid operation has been submitted.
2409
-  if (isset($form_state['values']['operation']) && isset($operations[$form_state['values']['operation']])) {
2407
+    // Check if a valid operation has been submitted.
2408
+    if (isset($form_state['values']['operation']) && isset($operations[$form_state['values']['operation']])) {
2410 2409
     $operation = $operations[$form_state['values']['operation']];
2411
-  }
2410
+    }
2412 2411
 
2413
-  // Load all keys where the value is the current op.
2414
-  $keys = array_keys($form_state['values'], $form_state['values']['op']);
2412
+    // Load all keys where the value is the current op.
2413
+    $keys = array_keys($form_state['values'], $form_state['values']['op']);
2415 2414
 
2416
-  // The first one is op itself, we need to use the second.
2417
-  if (isset($keys[1]) && isset($operations[$keys[1]])) {
2415
+    // The first one is op itself, we need to use the second.
2416
+    if (isset($keys[1]) && isset($operations[$keys[1]])) {
2418 2417
     $operation = $operations[$keys[1]];
2419
-  }
2418
+    }
2420 2419
 
2421
-  // Only execute something if we have a valid callback and at least one checked thread.
2422
-  if (!empty($operation['callback'])) {
2420
+    // Only execute something if we have a valid callback and at least one checked thread.
2421
+    if (!empty($operation['callback'])) {
2423 2422
     privatemsg_operation_execute($operation, $form_state['values']['threads'], $form_state['values']['account']);
2424
-  }
2423
+    }
2425 2424
 }
2426 2425
 
2427 2426
 /**
@@ -2435,42 +2434,42 @@  discard block
 block discarded – undo
2435 2434
  *   array can be directly passed to it.
2436 2435
  */
2437 2436
 function privatemsg_operation_execute($operation, $threads, $account = null) {
2438
-  // Filter out unchecked threads, this gives us an array of "checked" threads.
2439
-  $threads = array_filter($threads);
2437
+    // Filter out unchecked threads, this gives us an array of "checked" threads.
2438
+    $threads = array_filter($threads);
2440 2439
 
2441
-  if (empty($threads)) {
2440
+    if (empty($threads)) {
2442 2441
     // Do not execute anything if there are no checked threads.
2443 2442
     return;
2444
-  }
2445
-  // Add in callback arguments if present.
2446
-  if (isset($operation['callback arguments'])) {
2443
+    }
2444
+    // Add in callback arguments if present.
2445
+    if (isset($operation['callback arguments'])) {
2447 2446
     $args = array_merge(array($threads), $operation['callback arguments']);
2448
-  }
2449
-  else {
2447
+    }
2448
+    else {
2450 2449
     $args = array($threads);
2451
-  }
2450
+    }
2452 2451
 
2453
-  // Add the user object to the arguments.
2454
-  if ($account) {
2452
+    // Add the user object to the arguments.
2453
+    if ($account) {
2455 2454
     $args[] = $account;
2456
-  }
2455
+    }
2457 2456
 
2458
-  // Execute the chosen action and pass the defined arguments.
2459
-  call_user_func_array($operation['callback'], $args);
2457
+    // Execute the chosen action and pass the defined arguments.
2458
+    call_user_func_array($operation['callback'], $args);
2460 2459
 
2461
-  // Check if that operation has defined an undo callback.
2462
-  if (isset($operation['undo callback']) && $undo_function = $operation['undo callback']) {
2460
+    // Check if that operation has defined an undo callback.
2461
+    if (isset($operation['undo callback']) && $undo_function = $operation['undo callback']) {
2463 2462
     // Add in callback arguments if present.
2464 2463
     if (isset($operation['undo callback arguments'])) {
2465
-      $undo_args = array_merge(array($threads), $operation['undo callback arguments']);
2464
+        $undo_args = array_merge(array($threads), $operation['undo callback arguments']);
2466 2465
     }
2467 2466
     else {
2468
-      $undo_args = array($threads);
2467
+        $undo_args = array($threads);
2469 2468
     }
2470 2469
 
2471 2470
     // Avoid saving the complete user object in the session.
2472 2471
     if ($account) {
2473
-      $undo_args['account'] = $account->uid;
2472
+        $undo_args['account'] = $account->uid;
2474 2473
     }
2475 2474
     // Store the undo callback in the session and display a "Undo" link.
2476 2475
     // @todo: Provide a more flexible solution for such an undo action, operation defined string for example.
@@ -2478,7 +2477,7 @@  discard block
 block discarded – undo
2478 2477
     $undo = url('messages/undo/action', array('query' => drupal_get_destination()));
2479 2478
 
2480 2479
     drupal_set_message(t('The previous action can be <a href="!undo">undone</a>.', array('!undo' => $undo)));
2481
-  }
2480
+    }
2482 2481
 }
2483 2482
 
2484 2483
 /**
@@ -2494,71 +2493,71 @@  discard block
 block discarded – undo
2494 2493
  *   defaults to the current user.
2495 2494
  */
2496 2495
 function privatemsg_thread_change_delete($threads, $delete, $account = NULL) {
2497
-  if (!is_array($threads)) {
2496
+    if (!is_array($threads)) {
2498 2497
     $threads = array($threads);
2499
-  }
2500
-  if (empty($account)) {
2498
+    }
2499
+    if (empty($account)) {
2501 2500
     global $user;
2502 2501
     $account = drupal_clone($user);
2503
-  }
2502
+    }
2504 2503
 
2505
-  // Merge status and uid with the threads list. array_merge() will not overwrite/ignore thread_id 1.
2506
-  $params = array_merge(array($delete, $account->uid), $threads);
2504
+    // Merge status and uid with the threads list. array_merge() will not overwrite/ignore thread_id 1.
2505
+    $params = array_merge(array($delete, $account->uid), $threads);
2507 2506
 
2508
-  // Load all messages of those threads including the deleted.
2509
-  $query = _privatemsg_assemble_query('messages', $threads, $account, TRUE);
2510
-  $result = db_query($query['query']);
2507
+    // Load all messages of those threads including the deleted.
2508
+    $query = _privatemsg_assemble_query('messages', $threads, $account, TRUE);
2509
+    $result = db_query($query['query']);
2511 2510
 
2512
-  // Delete each message. We need to do that to trigger the delete hook.
2513
-  while ($row = db_fetch_array($result)) {
2511
+    // Delete each message. We need to do that to trigger the delete hook.
2512
+    while ($row = db_fetch_array($result)) {
2514 2513
     privatemsg_message_change_delete($row['mid'], $delete, $account);
2515
-  }
2514
+    }
2516 2515
 
2517
-  if ($delete) {
2516
+    if ($delete) {
2518 2517
     drupal_set_message(format_plural(count($threads), 'Deleted 1 thread.', 'Deleted @count threads.'));
2519
-  }
2520
-  else {
2518
+    }
2519
+    else {
2521 2520
     drupal_set_message(format_plural(count($threads), 'Restored 1 thread.', 'Restored @count threads.'));
2522
-  }
2521
+    }
2523 2522
 }
2524 2523
 
2525 2524
 /**
2526 2525
  * Implements hook_privatemsg_thread_operations().
2527 2526
  */
2528 2527
 function privatemsg_privatemsg_thread_operations() {
2529
-  $operations = array(
2528
+    $operations = array(
2530 2529
     'mark as read' => array(
2531
-      'label' => t('Mark as read'),
2532
-      'callback' => 'privatemsg_thread_change_status',
2533
-      'callback arguments' => array('status' => PRIVATEMSG_READ),
2534
-      'undo callback' => 'privatemsg_thread_change_status',
2535
-      'undo callback arguments' => array('status' => PRIVATEMSG_UNREAD),
2530
+        'label' => t('Mark as read'),
2531
+        'callback' => 'privatemsg_thread_change_status',
2532
+        'callback arguments' => array('status' => PRIVATEMSG_READ),
2533
+        'undo callback' => 'privatemsg_thread_change_status',
2534
+        'undo callback arguments' => array('status' => PRIVATEMSG_UNREAD),
2536 2535
     ),
2537 2536
     'mark as unread' => array(
2538
-      'label' => t('Mark as unread'),
2539
-      'callback' => 'privatemsg_thread_change_status',
2540
-      'callback arguments' => array('status' => PRIVATEMSG_UNREAD),
2541
-      'undo callback' => 'privatemsg_thread_change_status',
2542
-      'undo callback arguments' => array('status' => PRIVATEMSG_READ),
2537
+        'label' => t('Mark as unread'),
2538
+        'callback' => 'privatemsg_thread_change_status',
2539
+        'callback arguments' => array('status' => PRIVATEMSG_UNREAD),
2540
+        'undo callback' => 'privatemsg_thread_change_status',
2541
+        'undo callback arguments' => array('status' => PRIVATEMSG_READ),
2543 2542
     ),
2544
-  );
2545
-  if (privatemsg_user_access('delete privatemsg')) {
2543
+    );
2544
+    if (privatemsg_user_access('delete privatemsg')) {
2546 2545
     $operations['delete'] = array(
2547
-      'callback' => 'privatemsg_thread_change_delete',
2548
-      'callback arguments' => array('delete' => 1),
2549
-      'undo callback' => 'privatemsg_thread_change_delete',
2550
-      'undo callback arguments' => array('delete' => 0),
2546
+        'callback' => 'privatemsg_thread_change_delete',
2547
+        'callback arguments' => array('delete' => 1),
2548
+        'undo callback' => 'privatemsg_thread_change_delete',
2549
+        'undo callback arguments' => array('delete' => 0),
2551 2550
     );
2552
-  }
2553
-  return $operations;
2551
+    }
2552
+    return $operations;
2554 2553
 }
2555 2554
 
2556 2555
 /**
2557 2556
  * Implementation of hook_views_api().
2558 2557
  */
2559 2558
 function privatemsg_views_api() {
2560
-  return array(
2559
+    return array(
2561 2560
     'api' => 2,
2562 2561
     'path' => drupal_get_path('module', 'privatemsg') . '/views',
2563
-  );
2562
+    );
2564 2563
 }
Please login to merge, or discard this patch.
default/boinc/modules/contrib/privatemsg/pm_block_user/pm_block_user.module 1 patch
Indentation   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -19,17 +19,17 @@  discard block
 block discarded – undo
19 19
  * Implements hook_help().
20 20
  */
21 21
 function pm_block_user_help($path) {
22
-  switch ($path) {
22
+    switch ($path) {
23 23
     case 'admin/settings/messages/block':
24 24
       return '<p>' . t('This area is used to define user blocking rules for the Privatemsg module. Rules allow control of who may block messages from whom. By default all users are allowed to block messages from anyone else. However, a site may have groups of users that need to contact or get information to others, for example: the site may have administrative staff or be a forum with moderators. Groups of users are defined by roles, which can be managed on the <a href="@roles">roles configuration page</a>.', array('@roles' => url('admin/user/roles'))) . '</p>';
25
-  }
25
+    }
26 26
 }
27 27
 
28 28
 /**
29 29
  * Implements hook_menu().
30 30
  */
31 31
 function pm_block_user_menu() {
32
-  $items['messages/block/%user'] = array(
32
+    $items['messages/block/%user'] = array(
33 33
     'title'            => 'Block user messages',
34 34
     'page callback'    => 'drupal_get_form',
35 35
     'page arguments'   => array('pm_block_user_form', 2),
@@ -37,61 +37,61 @@  discard block
 block discarded – undo
37 37
     'access arguments' => array(2),
38 38
     'type'             => MENU_CALLBACK,
39 39
     'weight'           => -10,
40
-  );
40
+    );
41 41
 
42
-  $items['admin/settings/messages/block'] = array(
42
+    $items['admin/settings/messages/block'] = array(
43 43
     'title'            => 'User blocking rules',
44 44
     'description'      => 'Configure rules for which users may block each other.',
45 45
     'page callback'    => 'drupal_get_form',
46 46
     'page arguments'   => array('pm_block_user_settings'),
47 47
     'access arguments' => array('administer privatemsg settings'),
48 48
     'type'             => MENU_LOCAL_TASK,
49
-  );
49
+    );
50 50
 
51
-  $items['messages/block/js'] = array(
51
+    $items['messages/block/js'] = array(
52 52
     'title' => 'Javascript block actions form',
53 53
     'page callback' => 'pm_block_user_js',
54 54
     'access arguments' => array('administer privatemsg settings'),
55 55
     'type' => MENU_CALLBACK,
56
-  );
56
+    );
57 57
 
58
-  return $items;
58
+    return $items;
59 59
 }
60 60
 
61 61
 /**
62 62
  * Menu callback for blocked user settings.
63 63
  */
64 64
 function pm_block_user_settings(&$form_state) {
65
-  drupal_add_css(drupal_get_path('module', 'pm_block_user') .'/pm_block_user.css');
66
-  // Need to cache form for AHAH, so it can be rebuilt from cache later.
67
-  $form = array(
65
+    drupal_add_css(drupal_get_path('module', 'pm_block_user') .'/pm_block_user.css');
66
+    // Need to cache form for AHAH, so it can be rebuilt from cache later.
67
+    $form = array(
68 68
     '#cache' => TRUE,
69
-  );
69
+    );
70 70
 
71
-  // Container for just the actions, used for AHAH.
72
-  $form['block_actions'] = array(
71
+    // Container for just the actions, used for AHAH.
72
+    $form['block_actions'] = array(
73 73
     '#tree' => TRUE,
74 74
     '#prefix' => '<div id="block-actions">',
75 75
     '#suffix' => '</div>',
76 76
     '#theme' => 'pm_block_user_actions',
77
-  );
77
+    );
78 78
 
79
-  // Should we populate the form with data from $form_state or the database?
80
-  if (!isset($form_state['pm_block_user']['block_actions'])) {
79
+    // Should we populate the form with data from $form_state or the database?
80
+    if (!isset($form_state['pm_block_user']['block_actions'])) {
81 81
     $block_actions = variable_get('pm_block_user_actions', array());
82
-  }
83
-  else {
82
+    }
83
+    else {
84 84
     $block_actions = $form_state['pm_block_user']['block_actions'];
85
-  }
86
-  // Work through each rule, adding it as a new element in
87
-  // $form['block_actions'] ready to be themed later.
88
-  foreach ($block_actions as $delta => $details) {
85
+    }
86
+    // Work through each rule, adding it as a new element in
87
+    // $form['block_actions'] ready to be themed later.
88
+    foreach ($block_actions as $delta => $details) {
89 89
     $details['delta'] = $delta;
90 90
     $form['block_actions'][$delta] = _pm_block_user_actions_form($details);
91
-  }
91
+    }
92 92
 
93
-  // The magic AHAH callback button that adds more rows.
94
-  $form['pm_block_actions_more'] = array(
93
+    // The magic AHAH callback button that adds more rows.
94
+    $form['pm_block_actions_more'] = array(
95 95
     '#type' => 'submit',
96 96
     '#value' => t('More'),
97 97
     '#weight' => 1,
@@ -99,20 +99,20 @@  discard block
 block discarded – undo
99 99
     '#suffix' => '<label for="edit-pm-block-actions-more">' . t('Add new rule') . '</label></div>',
100 100
     '#submit' => array('pm_block_user_more_submit'),
101 101
     '#ahah' => array(
102
-      'path' => 'messages/block/js',
103
-      'wrapper' => 'block-actions',
104
-      'method' => 'replace',
105
-      'effect' => 'fade',
102
+        'path' => 'messages/block/js',
103
+        'wrapper' => 'block-actions',
104
+        'method' => 'replace',
105
+        'effect' => 'fade',
106 106
     ),
107
-  );
107
+    );
108 108
 
109
-  $form['submit_form'] = array(
109
+    $form['submit_form'] = array(
110 110
     '#type' => 'submit',
111 111
     '#weight' => 10,
112 112
     '#value' => t('Save configuration'),
113
-  );
113
+    );
114 114
 
115
-  return $form;
115
+    return $form;
116 116
 }
117 117
 
118 118
 /**
@@ -132,50 +132,50 @@  discard block
 block discarded – undo
132 132
  *   Part of a form with controls for sending, receiving and actions.
133 133
  */
134 134
 function _pm_block_user_actions_form($details, $blacklist = TRUE) {
135
-  $form = array(
135
+    $form = array(
136 136
     '#tree' => TRUE,
137
-  );
138
-  $delta = $details['delta'];
139
-  // FALSE by default, or if the user has checked the 'Enabled' check box for
140
-  // this row.
141
-  $row_disabled = (isset($details['enabled']) ? !$details['enabled'] : FALSE);
137
+    );
138
+    $delta = $details['delta'];
139
+    // FALSE by default, or if the user has checked the 'Enabled' check box for
140
+    // this row.
141
+    $row_disabled = (isset($details['enabled']) ? !$details['enabled'] : FALSE);
142 142
 
143
-  $form['author'] = array(
143
+    $form['author'] = array(
144 144
     '#type' => 'select',
145 145
     '#options' => user_roles(TRUE),
146 146
     '#default_value' => (isset($details['author']) ? $details['author'] : DRUPAL_AUTHENTICATED_RID),
147 147
     '#disabled' => $row_disabled,
148
-  );
149
-  $form['recipient'] = array(
148
+    );
149
+    $form['recipient'] = array(
150 150
     '#type' => 'select',
151 151
     '#options' => user_roles(TRUE),
152 152
     '#default_value' => (isset($details['recipient']) ? $details['recipient'] : DRUPAL_AUTHENTICATED_RID),
153 153
     '#disabled' => $row_disabled,
154
-  );
154
+    );
155 155
 
156
-  // Provide different action radios if we're using a whitelist or a blacklist.
157
-  if ($blacklist) {
156
+    // Provide different action radios if we're using a whitelist or a blacklist.
157
+    if ($blacklist) {
158 158
     $options = array(
159
-      PM_BLOCK_USER_DISALLOW_BLOCKING => t('Disallow blocking author'),
160
-      PM_BLOCK_USER_DISALLOW_SENDING => t('Disallow sending message'),
159
+        PM_BLOCK_USER_DISALLOW_BLOCKING => t('Disallow blocking author'),
160
+        PM_BLOCK_USER_DISALLOW_SENDING => t('Disallow sending message'),
161 161
     );
162 162
     $default_value = (isset($details['action']) ? $details['action'] : PM_BLOCK_USER_DISALLOW_BLOCKING);
163
-  }
164
-  else {
163
+    }
164
+    else {
165 165
     // @todo: add whitelist options/default_value here.
166
-  }
167
-  $form['action']  = array(
166
+    }
167
+    $form['action']  = array(
168 168
     '#type' => 'radios',
169 169
     '#options' => $options,
170 170
     '#disabled' => $row_disabled,
171 171
     '#default_value' => $default_value,
172
-  );
172
+    );
173 173
 
174
-  $form['enabled'] = array(
174
+    $form['enabled'] = array(
175 175
     '#type' => 'checkbox',
176 176
     '#default_value' => (isset($details['enabled']) ? $details['enabled'] : TRUE),
177
-  );
178
-  $form['remove'] = array(
177
+    );
178
+    $form['remove'] = array(
179 179
     '#type' => 'submit',
180 180
     '#submit' => array('pm_block_user_remove_submit'),
181 181
     '#value' => t('Remove'),
@@ -183,14 +183,14 @@  discard block
 block discarded – undo
183 183
     '#prefix' => '<div id="remove-rule-button">',
184 184
     '#suffix' => '<label for="edit-remove">' . t('Remove rule') . '</label></div>',
185 185
     '#ahah' => array(
186
-      'path' => 'messages/block/js',
187
-      'wrapper' => 'block-actions',
188
-      'method' => 'replace',
189
-      'effect' => 'fade',
186
+        'path' => 'messages/block/js',
187
+        'wrapper' => 'block-actions',
188
+        'method' => 'replace',
189
+        'effect' => 'fade',
190 190
     ),
191
-  );
191
+    );
192 192
 
193
-  return $form;
193
+    return $form;
194 194
 }
195 195
 
196 196
 /**
@@ -199,17 +199,17 @@  discard block
 block discarded – undo
199 199
  * @see pm_block_user_remove_submit()
200 200
  */
201 201
 function pm_block_user_more_submit($form, &$form_state) {
202
-  unset($form_state['submit_handlers']);
203
-  form_execute_handlers('submit', $form, $form_state);
204
-  // Get the submitted actions, then put them into a special area of
205
-  // the $form_state.
206
-  $submitted_values = $form_state['values'];
207
-  // Add an empty action.
208
-  $submitted_values['block_actions'][] = array();
209
-  $form_state['pm_block_user'] = $submitted_values;
210
-  // Rebuild the form by passing our $form_state through the
211
-  // pm_block_user_settings() builder function.
212
-  $form_state['rebuild'] = TRUE;
202
+    unset($form_state['submit_handlers']);
203
+    form_execute_handlers('submit', $form, $form_state);
204
+    // Get the submitted actions, then put them into a special area of
205
+    // the $form_state.
206
+    $submitted_values = $form_state['values'];
207
+    // Add an empty action.
208
+    $submitted_values['block_actions'][] = array();
209
+    $form_state['pm_block_user'] = $submitted_values;
210
+    // Rebuild the form by passing our $form_state through the
211
+    // pm_block_user_settings() builder function.
212
+    $form_state['rebuild'] = TRUE;
213 213
 }
214 214
 
215 215
 /**
@@ -218,33 +218,33 @@  discard block
 block discarded – undo
218 218
  * @see pm_block_user_more_submit()
219 219
  */
220 220
 function pm_block_user_remove_submit($form, &$form_state) {
221
-  unset($form_state['submit_handlers']);
222
-  form_execute_handlers('submit', $form, $form_state);
223
-  $submitted_values = $form_state['values'];
224
-  // Remove the requested action.
225
-  $delta = $form_state['clicked_button']['#parents'][1];
226
-  unset($submitted_values['block_actions'][$delta]);
227
-  $form_state['pm_block_user'] = $submitted_values;
228
-  $form_state['rebuild'] = TRUE;
221
+    unset($form_state['submit_handlers']);
222
+    form_execute_handlers('submit', $form, $form_state);
223
+    $submitted_values = $form_state['values'];
224
+    // Remove the requested action.
225
+    $delta = $form_state['clicked_button']['#parents'][1];
226
+    unset($submitted_values['block_actions'][$delta]);
227
+    $form_state['pm_block_user'] = $submitted_values;
228
+    $form_state['rebuild'] = TRUE;
229 229
 }
230 230
 
231 231
 /**
232 232
  * Submit handler for admin form.
233 233
  */
234 234
 function pm_block_user_settings_submit($form, &$form_state) {
235
-  // We don't want it to submit when we're adding/removing actions.
236
-  if ($form_state['clicked_button']['#id'] == 'edit-submit-form') {
235
+    // We don't want it to submit when we're adding/removing actions.
236
+    if ($form_state['clicked_button']['#id'] == 'edit-submit-form') {
237 237
     // If the form's 'block_actions' aren't set, the user has deleted all the
238 238
     // rows in the table, so we save an empty array to stop errors in the form
239 239
     // builder.
240 240
     if (isset($form_state['values']['block_actions'])) {
241
-      variable_set('pm_block_user_actions', _pm_block_user_settings_filter($form_state['values']['block_actions']));
241
+        variable_set('pm_block_user_actions', _pm_block_user_settings_filter($form_state['values']['block_actions']));
242 242
     }
243 243
     else {
244
-      variable_set('pm_block_user_actions', array());
244
+        variable_set('pm_block_user_actions', array());
245 245
     }
246 246
     drupal_set_message(t('The configuration options have been saved.'));
247
-  }
247
+    }
248 248
 }
249 249
 
250 250
 /**
@@ -259,60 +259,60 @@  discard block
 block discarded – undo
259 259
  * @see pm_block_user_settings_submit()
260 260
  */
261 261
 function _pm_block_user_settings_filter($settings) {
262
-  // Add-in the names of any settings to be saved into the array below.
263
-  $save_keys = array('author', 'recipient', 'action', 'enabled');
264
-  $matching = array();
265
-  // Run through each of the keys we want to save, creating a new array.
266
-  // It's not possible to simply check for unwanted values and unset() them as
267
-  // the array is multi-dimensional.
268
-  foreach ($save_keys as $save_key) {
262
+    // Add-in the names of any settings to be saved into the array below.
263
+    $save_keys = array('author', 'recipient', 'action', 'enabled');
264
+    $matching = array();
265
+    // Run through each of the keys we want to save, creating a new array.
266
+    // It's not possible to simply check for unwanted values and unset() them as
267
+    // the array is multi-dimensional.
268
+    foreach ($save_keys as $save_key) {
269 269
     if (isset($settings[$save_key])) {
270
-      $matching[$save_key] = $settings[$save_key];
270
+        $matching[$save_key] = $settings[$save_key];
271
+    }
271 272
     }
272
-  }
273
-  if (count($matching) > 0) {
273
+    if (count($matching) > 0) {
274 274
     return $matching;
275
-  }
276
-  else {
275
+    }
276
+    else {
277 277
     return array_map('_pm_block_user_settings_filter', $settings);
278
-  }
278
+    }
279 279
 }
280 280
 
281 281
 /**
282 282
  * Menu callback for AHAH handling.
283 283
  */
284 284
 function pm_block_user_js() {
285
-  // See: http://drupal.org/node/331941 for the philosophy of Drupal AHAH.
286
-  $form_state = array('storage' => NULL, 'submitted' => FALSE);
287
-  $form_build_id = $_POST['form_build_id'];
288
-  $form = form_get_cache($form_build_id, $form_state);
289
-  $args = $form['#parameters'];
290
-  $form_id = array_shift($args);
291
-  $form['#post'] = $_POST;
292
-  $form['#redirect'] = FALSE;
293
-  $form['#programmed'] = FALSE;
294
-  $form_state['post'] = $_POST;
295
-  drupal_process_form($form_id, $form, $form_state);
296
-  $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
297
-  $output_form = $form['block_actions'];
298
-  unset($output_form['#prefix'], $output_form['#suffix']); // Prevent duplicate wrappers.
299
-  $output = theme('status_messages') . drupal_render($output_form);
300
-
301
-  // Hack to make behaviours attach to new HTML controls (delete buttons in
302
-  // this case).
303
-  $javascript = drupal_add_js(NULL, NULL, 'header');
304
-  drupal_json(array('status' => TRUE, 'data' => $output));
285
+    // See: http://drupal.org/node/331941 for the philosophy of Drupal AHAH.
286
+    $form_state = array('storage' => NULL, 'submitted' => FALSE);
287
+    $form_build_id = $_POST['form_build_id'];
288
+    $form = form_get_cache($form_build_id, $form_state);
289
+    $args = $form['#parameters'];
290
+    $form_id = array_shift($args);
291
+    $form['#post'] = $_POST;
292
+    $form['#redirect'] = FALSE;
293
+    $form['#programmed'] = FALSE;
294
+    $form_state['post'] = $_POST;
295
+    drupal_process_form($form_id, $form, $form_state);
296
+    $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
297
+    $output_form = $form['block_actions'];
298
+    unset($output_form['#prefix'], $output_form['#suffix']); // Prevent duplicate wrappers.
299
+    $output = theme('status_messages') . drupal_render($output_form);
300
+
301
+    // Hack to make behaviours attach to new HTML controls (delete buttons in
302
+    // this case).
303
+    $javascript = drupal_add_js(NULL, NULL, 'header');
304
+    drupal_json(array('status' => TRUE, 'data' => $output));
305 305
 }
306 306
 
307 307
 /**
308 308
  * Implements hook_theme().
309 309
  */
310 310
 function pm_block_user_theme() {
311
-  return array(
311
+    return array(
312 312
     'pm_block_user_actions' => array(
313
-      'arguments' => array('form' => NULL),
313
+        'arguments' => array('form' => NULL),
314 314
     ),
315
-  );
315
+    );
316 316
 }
317 317
 
318 318
 /**
@@ -321,49 +321,49 @@  discard block
 block discarded – undo
321 321
  * @ingroup themeable
322 322
  */
323 323
 function theme_pm_block_user_actions($form) {
324
-  $rows = array();
325
-  $headers = array(
324
+    $rows = array();
325
+    $headers = array(
326 326
     t('If the author has the role'),
327 327
     t('And the recipient has the role'),
328 328
     t('Action'),
329 329
     t('Enabled'),
330 330
     '',
331
-  );
332
-  $form_data = element_children($form);
331
+    );
332
+    $form_data = element_children($form);
333 333
 
334
-  foreach ($form_data as $key) {
334
+    foreach ($form_data as $key) {
335 335
     // Build the table row.
336 336
     $row = array(
337
-      'data' => array(
337
+        'data' => array(
338 338
         array('data' => drupal_render($form[$key]['author'])),
339 339
         array('data' => drupal_render($form[$key]['recipient'])),
340 340
         array('data' => drupal_render($form[$key]['action'])),
341 341
         array('data' => drupal_render($form[$key]['enabled'])),
342 342
         array('data' => drupal_render($form[$key]['remove'])),
343
-      ),
343
+        ),
344 344
     );
345 345
 
346 346
     // Add additional attributes to the row, such as a class for this row.
347 347
     if (isset($form[$key]['#attributes'])) {
348
-      $row = array_merge($row, $form[$key]['#attributes']);
348
+        $row = array_merge($row, $form[$key]['#attributes']);
349 349
     }
350 350
     $rows[] = $row;
351
-  }
351
+    }
352 352
 
353
-  // If there are no rows, output some instructions for the user.
354
-  if (empty($form_data)) {
353
+    // If there are no rows, output some instructions for the user.
354
+    if (empty($form_data)) {
355 355
     $rows[] = array(
356
-      array(
356
+        array(
357 357
         'data' => t("No rules have been added. All users may block private messages from each other. To limit which users may be blocked, click 'Add new rule'."),
358 358
         'colspan' => '5',
359
-      ),
359
+        ),
360 360
     );
361
-  }
361
+    }
362 362
 
363
-  $output = theme('table', $headers, $rows);
364
-  $output .= drupal_render($form);
363
+    $output = theme('table', $headers, $rows);
364
+    $output .= drupal_render($form);
365 365
 
366
-  return $output;
366
+    return $output;
367 367
 }
368 368
 
369 369
 /**
@@ -377,14 +377,14 @@  discard block
 block discarded – undo
377 377
  *   TRUE if the user is allowed to block $account, or FALSE if not.
378 378
  */
379 379
 function _pm_block_user_access($account) {
380
-  global $user;
381
-  if (!privatemsg_user_access('read privatemsg', $user)) {
380
+    global $user;
381
+    if (!privatemsg_user_access('read privatemsg', $user)) {
382 382
     return FALSE;
383
-  }
384
-  if (_pm_block_user_rule_exists($account, $user, PM_BLOCK_USER_DISALLOW_BLOCKING)) {
383
+    }
384
+    if (_pm_block_user_rule_exists($account, $user, PM_BLOCK_USER_DISALLOW_BLOCKING)) {
385 385
     return FALSE;
386
-  }
387
-  return TRUE;
386
+    }
387
+    return TRUE;
388 388
 }
389 389
 
390 390
 /**
@@ -406,179 +406,179 @@  discard block
 block discarded – undo
406 406
  *   TRUE if a rule exists for the combination of author recipient and action.
407 407
  */
408 408
 function _pm_block_user_rule_exists($author, $recipient, $action = PM_BLOCK_USER_DISALLOW_BLOCKING) {
409
-  $block_actions = variable_get('pm_block_user_actions', array());
410
-  foreach ($block_actions as $delta => $details) {
409
+    $block_actions = variable_get('pm_block_user_actions', array());
410
+    foreach ($block_actions as $delta => $details) {
411 411
     // If this rule doesn't relate to $action, or it's disabled
412 412
     // ignore it and go to next loop iteration.
413 413
     if ($details['action'] != $action || !$details['enabled']) {
414
-      continue;
414
+        continue;
415 415
     }
416 416
     // There are no rules governing user one, but user one may have roles that
417 417
     // affect other users, so these exceptions are narrow in scope.
418 418
     // Disallow sending affects private message authors.
419 419
     if ($author->uid == 1 && $action == PM_BLOCK_USER_DISALLOW_SENDING) {
420
-      continue;
420
+        continue;
421 421
     }
422 422
     // Disallow blocking affects private message recipients.
423 423
     if ($recipient->uid == 1 && $action == PM_BLOCK_USER_DISALLOW_BLOCKING) {
424
-      continue;
424
+        continue;
425 425
     }
426 426
     // The author has a role matching the rule and so does the recipient.
427 427
     if (isset($author->roles[$details['author']]) && isset($recipient->roles[$details['recipient']])) {
428
-      return TRUE;
428
+        return TRUE;
429
+    }
429 430
     }
430
-  }
431
-  return FALSE;
431
+    return FALSE;
432 432
 }
433 433
 
434 434
 function pm_block_user_form($form_state, $author) {
435
-  global $user;
435
+    global $user;
436 436
 
437
-  $form['author'] = array(
437
+    $form['author'] = array(
438 438
     '#type' => 'value',
439 439
     '#value' => $author->uid,
440
-  );
440
+    );
441 441
     $form['recipient'] = array(
442 442
     '#type' => 'value',
443 443
     '#value' => $user->uid,
444
-  );
445
-  $form['author_name'] = array(
444
+    );
445
+    $form['author_name'] = array(
446 446
     '#type' => 'value',
447 447
     '#value' => $author->name,
448
-  );
449
-  $form['destination'] = array(
448
+    );
449
+    $form['destination'] = array(
450 450
     '#type' => 'value',
451 451
     '#value' => isset($_GET['destination']) ? $_GET['destination'] : 'messages/',
452
-  );
452
+    );
453 453
 
454
-  if (db_result(db_query('SELECT COUNT(recipient) FROM {pm_block_user} WHERE author = %d AND recipient = %d', $author->uid, $user->uid))) {
454
+    if (db_result(db_query('SELECT COUNT(recipient) FROM {pm_block_user} WHERE author = %d AND recipient = %d', $author->uid, $user->uid))) {
455 455
     $form['block_action'] = array(
456
-      '#type' => 'value',
457
-      '#value' => 'unblock_user',
456
+        '#type' => 'value',
457
+        '#value' => 'unblock_user',
458 458
     );
459 459
     return confirm_form($form,
460
-      t('You have previously blocked "@author" from sending you any more messages. Are you sure you want to unblock this user?', array('@author' => $author->name)),
461
-      isset($_GET['destination']) ? $_GET['destination'] : 'messages/',
462
-      t('This action cannot be undone.'),
463
-      t('Unblock @author', array('@author' => $author->name)),
464
-      t('Cancel')
460
+        t('You have previously blocked "@author" from sending you any more messages. Are you sure you want to unblock this user?', array('@author' => $author->name)),
461
+        isset($_GET['destination']) ? $_GET['destination'] : 'messages/',
462
+        t('This action cannot be undone.'),
463
+        t('Unblock @author', array('@author' => $author->name)),
464
+        t('Cancel')
465 465
     );
466
-  }
467
-  else {
466
+    }
467
+    else {
468 468
     $form['block_action'] = array(
469
-      '#type' => 'value',
470
-      '#value' => 'block_user',
469
+        '#type' => 'value',
470
+        '#value' => 'block_user',
471 471
     );
472 472
     return confirm_form($form,
473
-      t('Are you sure you want to block "@author" from sending you any more messages?', array('@author' => $author->name)),
474
-      isset($_GET['destination']) ? $_GET['destination'] : 'messages/',
475
-      '',
476
-      t('Block @author', array('@author' => $author->name)),
477
-      t('Cancel')
473
+        t('Are you sure you want to block "@author" from sending you any more messages?', array('@author' => $author->name)),
474
+        isset($_GET['destination']) ? $_GET['destination'] : 'messages/',
475
+        '',
476
+        t('Block @author', array('@author' => $author->name)),
477
+        t('Cancel')
478 478
     );
479
-  }
479
+    }
480 480
 }
481 481
 
482 482
 /**
483 483
  * Implements hook_form_submit().
484 484
  */
485 485
 function pm_block_user_form_submit($form, &$form_state) {
486
-  if ($form_state['values']['confirm']) {
486
+    if ($form_state['values']['confirm']) {
487 487
     switch ($form_state['values']['block_action']) {
488
-      case 'block_user':
488
+        case 'block_user':
489 489
         db_query('INSERT INTO {pm_block_user} (author, recipient) VALUES (%d, %d)', $form_state['values']['author'], $form_state['values']['recipient']);
490 490
         drupal_set_message(t('@author has been blocked from sending you any further messages.', array('@author' => $form_state['values']['author_name'])));
491
-      break;
492
-      case 'unblock_user':
491
+        break;
492
+        case 'unblock_user':
493 493
         db_query('DELETE FROM {pm_block_user} WHERE author = %d AND recipient = %d', $form_state['values']['author'], $form_state['values']['recipient']);
494 494
         drupal_set_message(t('@author is now allowed to send you new messages.', array('@author' => $form_state['values']['author_name'])));
495
-      break;
495
+        break;
496
+    }
496 497
     }
497
-  }
498
-  $form_state['redirect'] = $form_state['values']['destination'];
498
+    $form_state['redirect'] = $form_state['values']['destination'];
499 499
 }
500 500
 
501 501
 /**
502 502
  * Implements hook_privatemsg_block_message().
503 503
  */
504 504
 function pm_block_user_privatemsg_block_message($author, $recipients) {
505
-  $blocked = array();
506
-  // Loop through each recipient and ensure there is no rule blocking this
507
-  // author from sending them private messages. Use a reference, so when
508
-  // user_load() is needed here the array is updated, negating the need for
509
-  // further calls to user_load() later in the code.
510
-  foreach (array_keys($recipients) as $uid) {
505
+    $blocked = array();
506
+    // Loop through each recipient and ensure there is no rule blocking this
507
+    // author from sending them private messages. Use a reference, so when
508
+    // user_load() is needed here the array is updated, negating the need for
509
+    // further calls to user_load() later in the code.
510
+    foreach (array_keys($recipients) as $uid) {
511 511
 
512 512
     // Ensure we have a recipient user object which includes roles.
513 513
     if (!isset($recipients[$uid]->roles)) {
514
-      $recipients[$uid] = user_load($uid);
514
+        $recipients[$uid] = user_load($uid);
515 515
     }
516 516
     // Note: this is checks whether the author may send the message (see third
517 517
     // parameter). Further below is a check whether the recipient may block it.
518 518
     if (_pm_block_user_rule_exists($author, $recipients[$uid], PM_BLOCK_USER_DISALLOW_SENDING)) {
519
-      $blocked[] = array(
519
+        $blocked[] = array(
520 520
         'uid' => $uid,
521 521
         'message' => t('Sorry, private messaging rules forbid sending messages to !name.', array('!name' => $recipients[$uid]->name)),
522
-      );
522
+        );
523
+    }
523 524
     }
524
-  }
525 525
 
526
-  $args = array_merge(array($author->uid), array_keys($recipients));
527
-  $result = db_query('SELECT recipient FROM {pm_block_user} WHERE author = %d AND recipient IN ('. db_placeholders($recipients) .') GROUP BY recipient', $args);
528
-  while ($row = db_fetch_array($result)) {
526
+    $args = array_merge(array($author->uid), array_keys($recipients));
527
+    $result = db_query('SELECT recipient FROM {pm_block_user} WHERE author = %d AND recipient IN ('. db_placeholders($recipients) .') GROUP BY recipient', $args);
528
+    while ($row = db_fetch_array($result)) {
529 529
     $recipient = $recipients[$row['recipient']];
530 530
     // If there's a rule disallowing blocking of this message, send it anyway.
531 531
     if (_pm_block_user_rule_exists($author, $recipient, PM_BLOCK_USER_DISALLOW_BLOCKING)) {
532
-      continue;
532
+        continue;
533 533
     }
534 534
     $blocked[] = array(
535
-      'uid' => $row['recipient'],
536
-      'message' => t('%name has chosen to not recieve any more messages from you.', array('%name' => $recipients[$row['recipient']]->name))
535
+        'uid' => $row['recipient'],
536
+        'message' => t('%name has chosen to not recieve any more messages from you.', array('%name' => $recipients[$row['recipient']]->name))
537 537
     );
538
-  }
539
-  return $blocked;
538
+    }
539
+    return $blocked;
540 540
 }
541 541
 
542 542
 function pm_block_user_privatemsg_sql_load_alter(&$fragments, $pmid, $uid) {
543
-  $fragments['select'][] = 'pmbu.recipient AS is_blocked';
543
+    $fragments['select'][] = 'pmbu.recipient AS is_blocked';
544 544
 
545
-  $fragments['inner_join'][] = 'LEFT JOIN {pm_block_user} pmbu ON (pm.author = pmbu.author AND pmi.uid = pmbu.recipient)';
545
+    $fragments['inner_join'][] = 'LEFT JOIN {pm_block_user} pmbu ON (pm.author = pmbu.author AND pmi.uid = pmbu.recipient)';
546 546
 }
547 547
 
548 548
 /**
549 549
  * Implements hook_privatemsg_message_view_alter().
550 550
  */
551 551
 function pm_block_user_privatemsg_message_view_alter(&$vars) {
552
-  global $user;
552
+    global $user;
553 553
 
554
-  $author = $vars['message']['author'];
555
-  if (_pm_block_user_rule_exists($author, $user, PM_BLOCK_USER_DISALLOW_BLOCKING)) {
554
+    $author = $vars['message']['author'];
555
+    if (_pm_block_user_rule_exists($author, $user, PM_BLOCK_USER_DISALLOW_BLOCKING)) {
556 556
     return;
557
-  }
558
-  if (!isset($vars['message']['thread_id'])) {
557
+    }
558
+    if (!isset($vars['message']['thread_id'])) {
559 559
     // No thread id, this is probably only a preview
560 560
     return;
561
-  }
562
-  $thread_id = $vars['message']['thread_id'];
561
+    }
562
+    $thread_id = $vars['message']['thread_id'];
563 563
 
564
-  if ($user->uid <> $author->uid) {
564
+    if ($user->uid <> $author->uid) {
565 565
     if ($vars['message']['is_blocked']) {
566
-      $vars['message_actions']['unblock_author'] = array('title' => t('Unblock author'), 'href' => 'messages/block/'. $author->uid, 'query' => 'destination=messages/view/' . $thread_id);
566
+        $vars['message_actions']['unblock_author'] = array('title' => t('Unblock author'), 'href' => 'messages/block/'. $author->uid, 'query' => 'destination=messages/view/' . $thread_id);
567 567
     }
568 568
     else {
569
-      $vars['message_actions']['block_author'] = array('title' => t('Block author'), 'href' => 'messages/block/'. $author->uid, 'query' => 'destination=messages/view/' . $thread_id);
569
+        $vars['message_actions']['block_author'] = array('title' => t('Block author'), 'href' => 'messages/block/'. $author->uid, 'query' => 'destination=messages/view/' . $thread_id);
570
+    }
570 571
     }
571
-  }
572 572
 }
573 573
 
574 574
 /**
575 575
  * Implement hook_user().
576 576
  */
577 577
 function pm_block_user_user($op, &$edit, &$account, $category = NULL) {
578
-  switch ($op) {
579
-      case 'delete':
578
+    switch ($op) {
579
+        case 'delete':
580 580
       // Delete blocking rules which involve this user.
581 581
       db_query("DELETE FROM {pm_block_user} WHERE author = %d OR recipient = %d", $account->uid, $account->uid);
582
-      break;
583
-  }
582
+        break;
583
+    }
584 584
 }
Please login to merge, or discard this patch.
sites/default/boinc/modules/node_comment_block/node_comment_block.module 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -9,45 +9,45 @@  discard block
 block discarded – undo
9 9
  * Implements hook_block() for Drupal 6 compatibility
10 10
  */
11 11
 function node_comment_block_block($op = 'list', $delta = 0, $edit = array()) {
12
-  switch ($op) {
13
-  case 'view':
12
+    switch ($op) {
13
+    case 'view':
14 14
     //$block = node_comment_block_block_view($delta);
15 15
     $block = array();
16 16
     if ($delta == 'node_comments') {
17
-      if (arg(0) == 'node' && is_numeric($nid = arg(1)) && !arg(2)) {
17
+        if (arg(0) == 'node' && is_numeric($nid = arg(1)) && !arg(2)) {
18 18
         $node = node_load($nid);
19 19
         if ($node->comment !== 0) {
20
-          $block['subject'] = NULL; // This should be NULL otherwise there will be duplicate h2 elements.
21
-          $block['content'] = '';
22
-          if ($node->comment) {
20
+            $block['subject'] = NULL; // This should be NULL otherwise there will be duplicate h2 elements.
21
+            $block['content'] = '';
22
+            if ($node->comment) {
23 23
             $block['content'] .= comment_render($node);
24
-          }
24
+            }
25
+        }
25 26
         }
26
-      }
27 27
     }
28 28
     break;
29
-  case 'list':
29
+    case 'list':
30 30
     $blocks = node_comment_block_block_info();
31 31
     return $blocks;
32 32
     break;
33
-  default:
33
+    default:
34 34
   }
35
-  return $block;
35
+    return $block;
36 36
 }
37 37
 
38 38
 /**
39 39
  * Port Drupal 7 render() function to Drupal 6
40 40
  */
41 41
 function render(&$element) {
42
-  if (is_array($element)) {
42
+    if (is_array($element)) {
43 43
     show($element);
44 44
     return drupal_render($element);
45
-  }
46
-  else {
45
+    }
46
+    else {
47 47
     // Safe-guard for inappropriate use of render() on flat variables: return
48 48
     // the variable as-is.
49 49
     return $element;
50
-  }
50
+    }
51 51
 }
52 52
 
53 53
 
@@ -56,50 +56,50 @@  discard block
 block discarded – undo
56 56
  * Implements hook_block_info().
57 57
  */
58 58
 function node_comment_block_block_info() {
59
-  $blocks['node_comments'] = array(
59
+    $blocks['node_comments'] = array(
60 60
     'info' => t('Node comments'),
61
-  );
61
+    );
62 62
 
63
-  return $blocks;
63
+    return $blocks;
64 64
 }
65 65
 
66 66
 /**
67 67
  * Implements hook_block_view().
68 68
  */
69 69
 function node_comment_block_block_view($delta = '') {
70
-  $block = array();
70
+    $block = array();
71 71
 
72
-  if ($delta == 'node_comments') {
72
+    if ($delta == 'node_comments') {
73 73
     if (arg(0) == 'node' && is_numeric($nid = arg(1)) && !arg(2)) {
74
-      $node = node_load($nid);
74
+        $node = node_load($nid);
75 75
 
76
-      if ($node->comment !== 0) {
76
+        if ($node->comment !== 0) {
77 77
         $block['subject'] = NULL; // This should be NULL otherwise there will be duplicate h2 elements.
78 78
         $block['content'] = '';
79 79
 
80 80
         $node = node_view($node);
81 81
 
82 82
         if ($node['comments']) {
83
-          $block['content'] .= render($node['comments']);
83
+            $block['content'] .= render($node['comments']);
84
+        }
84 85
         }
85
-      }
86 86
     }
87
-  }
87
+    }
88 88
 
89
-  return $block;
89
+    return $block;
90 90
 }
91 91
 
92 92
 /**
93 93
  * Implements hook_preprocess_HOOK() for nodes.
94 94
  */
95 95
 function node_comment_block_preprocess_node(&$variables) {
96
-  $node = $variables['node'];
97
-  // Only hide standard comments for news content
98
-  if ($variables['type'] == 'news') {
96
+    $node = $variables['node'];
97
+    // Only hide standard comments for news content
98
+    if ($variables['type'] == 'news') {
99 99
     $variables['node']->comment = 0;
100
-  }
100
+    }
101 101
   
102
-  /* Drupal 7...
102
+    /* Drupal 7...
103 103
   if ($node->comment !== 0 && $variables['view_mode'] == 'full') {
104 104
     if (isset($variables['content']['comments'])) {
105 105
       unset($variables['content']['comments']);
@@ -113,10 +113,10 @@  discard block
 block discarded – undo
113 113
  * Implements hook_form_FORM_ID_alter() for block_admin_configure.
114 114
  */
115 115
 function node_comment_block_form_block_admin_configure_alter(&$form, &$form_state) {
116
-  if (isset($form['delta'])) {
116
+    if (isset($form['delta'])) {
117 117
     if ($form['delta']['#value'] == 'node_comments') {
118
-      $form['settings']['title']['#disabled'] = TRUE;
119
-      $form['settings']['title']['#description'] = t('The title for this block cannot be overridden.');
118
+        $form['settings']['title']['#disabled'] = TRUE;
119
+        $form['settings']['title']['#description'] = t('The title for this block cannot be overridden.');
120
+    }
120 121
     }
121
-  }
122 122
 }
Please login to merge, or discard this patch.
default/boinc/modules/boincstats/includes/pchart/class/pBarcode39.class.php 1 patch
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
- /*
2
+    /*
3 3
      pBarcode39 - class to create barcodes (39B)
4 4
 
5 5
      Version     : 2.1.3
@@ -13,188 +13,188 @@  discard block
 block discarded – undo
13 13
      You can find the whole class documentation on the pChart web site.
14 14
  */
15 15
 
16
- /* pData class definition */
17
- class pBarcode39
18
-  {
19
-   var $Codes;
20
-   var $Reverse;
21
-   var $Result;
22
-   var $pChartObject;
23
-   var $CRC;
24
-   var $MOD43;
25
-
26
-   /* Class creator */
27
-   function pBarcode39($BasePath="",$EnableMOD43=FALSE)
16
+    /* pData class definition */
17
+    class pBarcode39
28 18
     {
29
-     $this->MOD43  = $EnableMOD43;
30
-     $this->Codes   = "";
31
-     $this->Reverse = "";
19
+    var $Codes;
20
+    var $Reverse;
21
+    var $Result;
22
+    var $pChartObject;
23
+    var $CRC;
24
+    var $MOD43;
25
+
26
+    /* Class creator */
27
+    function pBarcode39($BasePath="",$EnableMOD43=FALSE)
28
+    {
29
+        $this->MOD43  = $EnableMOD43;
30
+        $this->Codes   = "";
31
+        $this->Reverse = "";
32 32
 
33
-     $FileHandle = @fopen($BasePath."data/39.db", "r");
33
+        $FileHandle = @fopen($BasePath."data/39.db", "r");
34 34
 
35
-     if (!$FileHandle) { die("Cannot find barcode database (".$BasePath."data/39.db)."); }
35
+        if (!$FileHandle) { die("Cannot find barcode database (".$BasePath."data/39.db)."); }
36 36
 
37
-     while (!feof($FileHandle))
38
-      {
39
-       $Buffer = fgets($FileHandle,4096);
40
-       $Buffer = str_replace(chr(10),"",$Buffer);
41
-       $Buffer = str_replace(chr(13),"",$Buffer);
42
-       $Values = preg_split("/;/",$Buffer);
37
+        while (!feof($FileHandle))
38
+        {
39
+        $Buffer = fgets($FileHandle,4096);
40
+        $Buffer = str_replace(chr(10),"",$Buffer);
41
+        $Buffer = str_replace(chr(13),"",$Buffer);
42
+        $Values = preg_split("/;/",$Buffer);
43 43
 
44
-       $this->Codes[$Values[0]] = $Values[1];
45
-      }
46
-     fclose($FileHandle);
44
+        $this->Codes[$Values[0]] = $Values[1];
45
+        }
46
+        fclose($FileHandle);
47 47
     }
48 48
 
49
-   /* Return the projected size of a barcode */
50
-   function getSize($TextString,$Format="")
49
+    /* Return the projected size of a barcode */
50
+    function getSize($TextString,$Format="")
51 51
     {
52
-     $Angle		= isset($Format["Angle"]) ? $Format["Angle"] : 0;
53
-     $ShowLegend	= isset($Format["ShowLegend"]) ? $Format["ShowLegend"] : FALSE;
54
-     $LegendOffset	= isset($Format["LegendOffset"]) ? $Format["LegendOffset"] : 5;
55
-     $DrawArea		= isset($Format["DrawArea"]) ? $Format["DrawArea"] : FALSE;
56
-     $FontSize		= isset($Format["FontSize"]) ? $Format["FontSize"] : 12;
57
-     $Height		= isset($Format["Height"]) ? $Format["Height"] : 30;
52
+        $Angle		= isset($Format["Angle"]) ? $Format["Angle"] : 0;
53
+        $ShowLegend	= isset($Format["ShowLegend"]) ? $Format["ShowLegend"] : FALSE;
54
+        $LegendOffset	= isset($Format["LegendOffset"]) ? $Format["LegendOffset"] : 5;
55
+        $DrawArea		= isset($Format["DrawArea"]) ? $Format["DrawArea"] : FALSE;
56
+        $FontSize		= isset($Format["FontSize"]) ? $Format["FontSize"] : 12;
57
+        $Height		= isset($Format["Height"]) ? $Format["Height"] : 30;
58 58
 
59
-     $TextString    = $this->encode39($TextString);
60
-     $BarcodeLength = strlen($this->Result);
59
+        $TextString    = $this->encode39($TextString);
60
+        $BarcodeLength = strlen($this->Result);
61 61
 
62
-     if ( $DrawArea )   { $WOffset = 20; } else { $WOffset = 0; }
63
-     if ( $ShowLegend ) { $HOffset = $FontSize+$LegendOffset+$WOffset; } else { $HOffset = 0; }
62
+        if ( $DrawArea )   { $WOffset = 20; } else { $WOffset = 0; }
63
+        if ( $ShowLegend ) { $HOffset = $FontSize+$LegendOffset+$WOffset; } else { $HOffset = 0; }
64 64
 
65
-     $X1 = cos($Angle * PI / 180) * ($WOffset+$BarcodeLength);
66
-     $Y1 = sin($Angle * PI / 180) * ($WOffset+$BarcodeLength);
65
+        $X1 = cos($Angle * PI / 180) * ($WOffset+$BarcodeLength);
66
+        $Y1 = sin($Angle * PI / 180) * ($WOffset+$BarcodeLength);
67 67
 
68
-     $X2 = $X1 + cos(($Angle+90) * PI / 180) * ($HOffset+$Height);
69
-     $Y2 = $Y1 + sin(($Angle+90) * PI / 180) * ($HOffset+$Height);
68
+        $X2 = $X1 + cos(($Angle+90) * PI / 180) * ($HOffset+$Height);
69
+        $Y2 = $Y1 + sin(($Angle+90) * PI / 180) * ($HOffset+$Height);
70 70
 
71 71
 
72
-     $AreaWidth  = max(abs($X1),abs($X2));
73
-     $AreaHeight = max(abs($Y1),abs($Y2));
72
+        $AreaWidth  = max(abs($X1),abs($X2));
73
+        $AreaHeight = max(abs($Y1),abs($Y2));
74 74
 
75
-     return(array("Width"=>$AreaWidth,"Height"=>$AreaHeight));
75
+        return(array("Width"=>$AreaWidth,"Height"=>$AreaHeight));
76 76
     }
77 77
 
78
-   /* Create the encoded string */
79
-   function encode39($Value)
78
+    /* Create the encoded string */
79
+    function encode39($Value)
80 80
     {
81
-     $this->Result = "100101101101"."0";
82
-     $TextString   = "";
83
-     for($i=1;$i<=strlen($Value);$i++)
84
-      {
85
-       $CharCode = ord($this->mid($Value,$i,1));
86
-       if ( $CharCode >= 97 && $CharCode <= 122 ) { $CharCode = $CharCode - 32; }
87
-
88
-       if ( isset($this->Codes[chr($CharCode)]) )
81
+        $this->Result = "100101101101"."0";
82
+        $TextString   = "";
83
+        for($i=1;$i<=strlen($Value);$i++)
84
+        {
85
+        $CharCode = ord($this->mid($Value,$i,1));
86
+        if ( $CharCode >= 97 && $CharCode <= 122 ) { $CharCode = $CharCode - 32; }
87
+
88
+        if ( isset($this->Codes[chr($CharCode)]) )
89 89
         {
90
-         $this->Result = $this->Result.$this->Codes[chr($CharCode)]."0";
91
-         $TextString = $TextString.chr($CharCode);
90
+            $this->Result = $this->Result.$this->Codes[chr($CharCode)]."0";
91
+            $TextString = $TextString.chr($CharCode);
92
+        }
92 93
         }
93
-      }
94 94
 
95
-     if ( $this->MOD43 )
96
-      {
97
-       $Checksum = $this->checksum($TextString);
98
-       $this->Result = $this->Result.$this->Codes[$Checksum]."0";
99
-      }
95
+        if ( $this->MOD43 )
96
+        {
97
+        $Checksum = $this->checksum($TextString);
98
+        $this->Result = $this->Result.$this->Codes[$Checksum]."0";
99
+        }
100 100
 
101
-     $this->Result = $this->Result."100101101101";
102
-     $TextString   = "*".$TextString."*";
101
+        $this->Result = $this->Result."100101101101";
102
+        $TextString   = "*".$TextString."*";
103 103
 
104
-     return($TextString);
104
+        return($TextString);
105 105
     }
106 106
 
107
-   /* Create the encoded string */
108
-   function draw($Object,$Value,$X,$Y,$Format="")
107
+    /* Create the encoded string */
108
+    function draw($Object,$Value,$X,$Y,$Format="")
109 109
     {
110
-     $this->pChartObject = $Object;
111
-
112
-     $R			= isset($Format["R"]) ? $Format["R"] : 0;
113
-     $G			= isset($Format["G"]) ? $Format["G"] : 0;
114
-     $B			= isset($Format["B"]) ? $Format["B"] : 0;
115
-     $Alpha		= isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
116
-     $Height		= isset($Format["Height"]) ? $Format["Height"] : 30;
117
-     $Angle		= isset($Format["Angle"]) ? $Format["Angle"] : 0;
118
-     $ShowLegend	= isset($Format["ShowLegend"]) ? $Format["ShowLegend"] : FALSE;
119
-     $LegendOffset	= isset($Format["LegendOffset"]) ? $Format["LegendOffset"] : 5;
120
-     $DrawArea		= isset($Format["DrawArea"]) ? $Format["DrawArea"] : FALSE;
121
-     $AreaR		= isset($Format["AreaR"]) ? $Format["AreaR"] : 255;
122
-     $AreaG		= isset($Format["AreaG"]) ? $Format["AreaG"] : 255;
123
-     $AreaB		= isset($Format["AreaB"]) ? $Format["AreaB"] : 255;
124
-     $AreaBorderR	= isset($Format["AreaBorderR"]) ? $Format["AreaBorderR"] : $AreaR;
125
-     $AreaBorderG	= isset($Format["AreaBorderG"]) ? $Format["AreaBorderG"] : $AreaG;
126
-     $AreaBorderB	= isset($Format["AreaBorderB"]) ? $Format["AreaBorderB"] : $AreaB;
127
-
128
-     $TextString   = $this->encode39($Value);
129
-
130
-     if ( $DrawArea )
131
-      {
132
-       $X1 = $X + cos(($Angle-135) * PI / 180) * 10;
133
-       $Y1 = $Y + sin(($Angle-135) * PI / 180) * 10;
134
-
135
-       $X2 = $X1 + cos($Angle * PI / 180) * (strlen($this->Result)+20);
136
-       $Y2 = $Y1 + sin($Angle * PI / 180) * (strlen($this->Result)+20);
137
-
138
-       if ( $ShowLegend )
110
+        $this->pChartObject = $Object;
111
+
112
+        $R			= isset($Format["R"]) ? $Format["R"] : 0;
113
+        $G			= isset($Format["G"]) ? $Format["G"] : 0;
114
+        $B			= isset($Format["B"]) ? $Format["B"] : 0;
115
+        $Alpha		= isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
116
+        $Height		= isset($Format["Height"]) ? $Format["Height"] : 30;
117
+        $Angle		= isset($Format["Angle"]) ? $Format["Angle"] : 0;
118
+        $ShowLegend	= isset($Format["ShowLegend"]) ? $Format["ShowLegend"] : FALSE;
119
+        $LegendOffset	= isset($Format["LegendOffset"]) ? $Format["LegendOffset"] : 5;
120
+        $DrawArea		= isset($Format["DrawArea"]) ? $Format["DrawArea"] : FALSE;
121
+        $AreaR		= isset($Format["AreaR"]) ? $Format["AreaR"] : 255;
122
+        $AreaG		= isset($Format["AreaG"]) ? $Format["AreaG"] : 255;
123
+        $AreaB		= isset($Format["AreaB"]) ? $Format["AreaB"] : 255;
124
+        $AreaBorderR	= isset($Format["AreaBorderR"]) ? $Format["AreaBorderR"] : $AreaR;
125
+        $AreaBorderG	= isset($Format["AreaBorderG"]) ? $Format["AreaBorderG"] : $AreaG;
126
+        $AreaBorderB	= isset($Format["AreaBorderB"]) ? $Format["AreaBorderB"] : $AreaB;
127
+
128
+        $TextString   = $this->encode39($Value);
129
+
130
+        if ( $DrawArea )
139 131
         {
140
-         $X3 = $X2 + cos(($Angle+90) * PI / 180) * ($Height+$LegendOffset+$this->pChartObject->FontSize+10);
141
-         $Y3 = $Y2 + sin(($Angle+90) * PI / 180) * ($Height+$LegendOffset+$this->pChartObject->FontSize+10);
132
+        $X1 = $X + cos(($Angle-135) * PI / 180) * 10;
133
+        $Y1 = $Y + sin(($Angle-135) * PI / 180) * 10;
134
+
135
+        $X2 = $X1 + cos($Angle * PI / 180) * (strlen($this->Result)+20);
136
+        $Y2 = $Y1 + sin($Angle * PI / 180) * (strlen($this->Result)+20);
137
+
138
+        if ( $ShowLegend )
139
+        {
140
+            $X3 = $X2 + cos(($Angle+90) * PI / 180) * ($Height+$LegendOffset+$this->pChartObject->FontSize+10);
141
+            $Y3 = $Y2 + sin(($Angle+90) * PI / 180) * ($Height+$LegendOffset+$this->pChartObject->FontSize+10);
142 142
         }
143
-       else
143
+        else
144 144
         {
145
-         $X3 = $X2 + cos(($Angle+90) * PI / 180) * ($Height+20);
146
-         $Y3 = $Y2 + sin(($Angle+90) * PI / 180) * ($Height+20);
145
+            $X3 = $X2 + cos(($Angle+90) * PI / 180) * ($Height+20);
146
+            $Y3 = $Y2 + sin(($Angle+90) * PI / 180) * ($Height+20);
147 147
         }
148 148
 
149
-       $X4 = $X3 + cos(($Angle+180) * PI / 180) * (strlen($this->Result)+20);
150
-       $Y4 = $Y3 + sin(($Angle+180) * PI / 180) * (strlen($this->Result)+20);
149
+        $X4 = $X3 + cos(($Angle+180) * PI / 180) * (strlen($this->Result)+20);
150
+        $Y4 = $Y3 + sin(($Angle+180) * PI / 180) * (strlen($this->Result)+20);
151 151
 
152
-       $Polygon  = array($X1,$Y1,$X2,$Y2,$X3,$Y3,$X4,$Y4);
153
-       $Settings = array("R"=>$AreaR,"G"=>$AreaG,"B"=>$AreaB,"BorderR"=>$AreaBorderR,"BorderG"=>$AreaBorderG,"BorderB"=>$AreaBorderB);
154
-       $this->pChartObject->drawPolygon($Polygon,$Settings);
155
-      }
152
+        $Polygon  = array($X1,$Y1,$X2,$Y2,$X3,$Y3,$X4,$Y4);
153
+        $Settings = array("R"=>$AreaR,"G"=>$AreaG,"B"=>$AreaB,"BorderR"=>$AreaBorderR,"BorderG"=>$AreaBorderG,"BorderB"=>$AreaBorderB);
154
+        $this->pChartObject->drawPolygon($Polygon,$Settings);
155
+        }
156 156
 
157
-     for($i=1;$i<=strlen($this->Result);$i++)
158
-      {
159
-       if ( $this->mid($this->Result,$i,1) == 1 )
157
+        for($i=1;$i<=strlen($this->Result);$i++)
158
+        {
159
+        if ( $this->mid($this->Result,$i,1) == 1 )
160 160
         {
161
-         $X1 = $X + cos($Angle * PI / 180) * $i;
162
-         $Y1 = $Y + sin($Angle * PI / 180) * $i;
163
-         $X2 = $X1 + cos(($Angle+90) * PI / 180) * $Height;
164
-         $Y2 = $Y1 + sin(($Angle+90) * PI / 180) * $Height;
161
+            $X1 = $X + cos($Angle * PI / 180) * $i;
162
+            $Y1 = $Y + sin($Angle * PI / 180) * $i;
163
+            $X2 = $X1 + cos(($Angle+90) * PI / 180) * $Height;
164
+            $Y2 = $Y1 + sin(($Angle+90) * PI / 180) * $Height;
165 165
 
166
-         $Settings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
167
-         $this->pChartObject->drawLine($X1,$Y1,$X2,$Y2,$Settings);
166
+            $Settings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
167
+            $this->pChartObject->drawLine($X1,$Y1,$X2,$Y2,$Settings);
168
+        }
168 169
         }
169
-      }
170 170
 
171
-     if ( $ShowLegend )
172
-      {
173
-       $X1 = $X + cos($Angle * PI / 180) * (strlen($this->Result)/2);
174
-       $Y1 = $Y + sin($Angle * PI / 180) * (strlen($this->Result)/2);
171
+        if ( $ShowLegend )
172
+        {
173
+        $X1 = $X + cos($Angle * PI / 180) * (strlen($this->Result)/2);
174
+        $Y1 = $Y + sin($Angle * PI / 180) * (strlen($this->Result)/2);
175 175
 
176
-       $LegendX = $X1 + cos(($Angle+90) * PI / 180) * ($Height+$LegendOffset);
177
-       $LegendY = $Y1 + sin(($Angle+90) * PI / 180) * ($Height+$LegendOffset);
176
+        $LegendX = $X1 + cos(($Angle+90) * PI / 180) * ($Height+$LegendOffset);
177
+        $LegendY = $Y1 + sin(($Angle+90) * PI / 180) * ($Height+$LegendOffset);
178 178
 
179
-       $Settings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Angle"=>-$Angle,"Align"=>TEXT_ALIGN_TOPMIDDLE);
180
-       $this->pChartObject->drawText($LegendX,$LegendY,$TextString,$Settings);
181
-      }
179
+        $Settings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Angle"=>-$Angle,"Align"=>TEXT_ALIGN_TOPMIDDLE);
180
+        $this->pChartObject->drawText($LegendX,$LegendY,$TextString,$Settings);
181
+        }
182 182
     }
183 183
 
184
-   function checksum( $string )
184
+    function checksum( $string )
185 185
     {
186
-     $checksum = 0;
187
-     $length   = strlen( $string );
188
-     $charset  = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%';
186
+        $checksum = 0;
187
+        $length   = strlen( $string );
188
+        $charset  = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%';
189 189
 
190
-     for( $i=0; $i < $length; ++$i )
191
-      $checksum += strpos( $charset, $string[$i] );
190
+        for( $i=0; $i < $length; ++$i )
191
+        $checksum += strpos( $charset, $string[$i] );
192 192
  
193
-     return substr( $charset, ($checksum % 43), 1 );
193
+        return substr( $charset, ($checksum % 43), 1 );
194 194
     }
195 195
 
196
-   function left($value,$NbChar) { return substr($value,0,$NbChar); }  
197
-   function right($value,$NbChar) { return substr($value,strlen($value)-$NbChar,$NbChar); }  
198
-   function mid($value,$Depart,$NbChar) { return substr($value,$Depart-1,$NbChar); }  
199
-  }
196
+    function left($value,$NbChar) { return substr($value,0,$NbChar); }  
197
+    function right($value,$NbChar) { return substr($value,strlen($value)-$NbChar,$NbChar); }  
198
+    function mid($value,$Depart,$NbChar) { return substr($value,$Depart-1,$NbChar); }  
199
+    }
200 200
 ?>
201 201
\ No newline at end of file
Please login to merge, or discard this patch.
default/boinc/modules/boincstats/includes/pchart/class/pIndicator.class.php 1 patch
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
- /*
2
+    /*
3 3
      pIndicator - class to draw indicators
4 4
 
5 5
      Version     : 2.1.3
@@ -13,229 +13,229 @@  discard block
 block discarded – undo
13 13
      You can find the whole class documentation on the pChart web site.
14 14
  */
15 15
 
16
- define("INDICATOR_CAPTION_DEFAULT"	, 700001);
17
- define("INDICATOR_CAPTION_EXTENDED"	, 700002);
16
+    define("INDICATOR_CAPTION_DEFAULT"	, 700001);
17
+    define("INDICATOR_CAPTION_EXTENDED"	, 700002);
18 18
 
19
- define("INDICATOR_CAPTION_INSIDE"	, 700011);
20
- define("INDICATOR_CAPTION_BOTTOM"	, 700012);
19
+    define("INDICATOR_CAPTION_INSIDE"	, 700011);
20
+    define("INDICATOR_CAPTION_BOTTOM"	, 700012);
21 21
 
22
- define("INDICATOR_VALUE_BUBBLE"	, 700021);
23
- define("INDICATOR_VALUE_LABEL"		, 700022);
22
+    define("INDICATOR_VALUE_BUBBLE"	, 700021);
23
+    define("INDICATOR_VALUE_LABEL"		, 700022);
24 24
 
25
- /* pIndicator class definition */
26
- class pIndicator
27
-  {
28
-   var $pChartObject;
25
+    /* pIndicator class definition */
26
+    class pIndicator
27
+    {
28
+    var $pChartObject;
29 29
 
30
-   /* Class creator */
31
-   function pIndicator($pChartObject)
30
+    /* Class creator */
31
+    function pIndicator($pChartObject)
32 32
     {
33
-     $this->pChartObject = $pChartObject;
33
+        $this->pChartObject = $pChartObject;
34 34
     }
35 35
 
36
-   /* Draw an indicator */
37
-   function draw($X,$Y,$Width,$Height,$Format="")
36
+    /* Draw an indicator */
37
+    function draw($X,$Y,$Width,$Height,$Format="")
38 38
     {
39
-     $Values			= isset($Format["Values"]) ? $Format["Values"] : VOID;
40
-     $IndicatorSections		= isset($Format["IndicatorSections"]) ? $Format["IndicatorSections"] : NULL;
41
-     $ValueDisplay		= isset($Format["ValueDisplay"]) ? $Format["ValueDisplay"] : INDICATOR_VALUE_BUBBLE;
42
-     $SectionsMargin		= isset($Format["SectionsMargin"]) ? $Format["SectionsMargin"] : 4;
43
-     $DrawLeftHead		= isset($Format["DrawLeftHead"]) ? $Format["DrawLeftHead"] : TRUE;
44
-     $DrawRightHead		= isset($Format["DrawRightHead"]) ? $Format["DrawRightHead"] : TRUE;
45
-     $HeadSize			= isset($Format["HeadSize"]) ? $Format["HeadSize"] : floor($Height/4);
46
-     $TextPadding		= isset($Format["TextPadding"]) ? $Format["TextPadding"] : 4;
47
-     $CaptionLayout		= isset($Format["CaptionLayout"]) ? $Format["CaptionLayout"] : INDICATOR_CAPTION_EXTENDED;
48
-     $CaptionPosition		= isset($Format["CaptionPosition"]) ? $Format["CaptionPosition"] : INDICATOR_CAPTION_INSIDE;
49
-     $CaptionColorFactor	= isset($Format["CaptionColorFactor"]) ? $Format["CaptionColorFactor"] : NULL;
50
-     $CaptionR			= isset($Format["CaptionR"]) ? $Format["CaptionR"] : 255;
51
-     $CaptionG			= isset($Format["CaptionG"]) ? $Format["CaptionG"] : 255;
52
-     $CaptionB			= isset($Format["CaptionB"]) ? $Format["CaptionB"] : 255;
53
-     $CaptionAlpha		= isset($Format["CaptionAlpha"]) ? $Format["CaptionAlpha"] : 100;
54
-     $SubCaptionColorFactor	= isset($Format["SubCaptionColorFactor"]) ? $Format["SubCaptionColorFactor"] : NULL;
55
-     $SubCaptionR		= isset($Format["SubCaptionR"]) ? $Format["SubCaptionR"] : 50;
56
-     $SubCaptionG		= isset($Format["SubCaptionG"]) ? $Format["SubCaptionG"] : 50;
57
-     $SubCaptionB		= isset($Format["SubCaptionB"]) ? $Format["SubCaptionB"] : 50;
58
-     $SubCaptionAlpha		= isset($Format["SubCaptionAlpha"]) ? $Format["SubCaptionAlpha"] : 100;
59
-     $ValueFontName		= isset($Format["ValueFontName"]) ? $Format["ValueFontName"] : $this->pChartObject->FontName;
60
-     $ValueFontSize		= isset($Format["ValueFontSize"]) ? $Format["ValueFontSize"] : $this->pChartObject->FontSize;
61
-     $CaptionFontName		= isset($Format["CaptionFontName"]) ? $Format["CaptionFontName"] : $this->pChartObject->FontName;
62
-     $CaptionFontSize		= isset($Format["CaptionFontSize"]) ? $Format["CaptionFontSize"] : $this->pChartObject->FontSize;
63
-     $Unit			= isset($Format["Unit"]) ? $Format["Unit"] : "";
64
-
65
-     /* Convert the Values to display to an array if needed */
66
-     if ( !is_array($Values) ) { $Value = $Values; $Values = ""; $Values[] = $Value; }
67
-
68
-     /* No section, let's die */
69
-     if ( $IndicatorSections == NULL ) { return(0); }
70
-
71
-     /* Determine indicator visual configuration */
72
-     $OverallMin = $IndicatorSections[0]["End"]; $OverallMax = $IndicatorSections[0]["Start"];
73
-     foreach ($IndicatorSections as $Key => $Settings)
74
-      {
75
-       if ( $Settings["End"] > $OverallMax )   { $OverallMax = $Settings["End"]; }
76
-       if ( $Settings["Start"] < $OverallMin ) { $OverallMin = $Settings["Start"]; }
77
-      }
78
-     $RealWidth = $Width - (count($IndicatorSections)-1)*$SectionsMargin;
79
-     $XScale    = $RealWidth / ($OverallMax-$OverallMin);
80
-
81
-     $X1 = $X; $ValuesPos = "";
82
-     foreach ($IndicatorSections as $Key => $Settings)
83
-      {
84
-       $Color      = array("R"=>$Settings["R"],"G"=>$Settings["G"],"B"=>$Settings["B"]);
85
-       $Caption    = $Settings["Caption"];
86
-       $SubCaption = $Settings["Start"]." - ".$Settings["End"];
87
-
88
-       $X2 = $X1 + ($Settings["End"] - $Settings["Start"]) * $XScale;
89
-
90
-       if ( $Key == 0 && $DrawLeftHead )
39
+        $Values			= isset($Format["Values"]) ? $Format["Values"] : VOID;
40
+        $IndicatorSections		= isset($Format["IndicatorSections"]) ? $Format["IndicatorSections"] : NULL;
41
+        $ValueDisplay		= isset($Format["ValueDisplay"]) ? $Format["ValueDisplay"] : INDICATOR_VALUE_BUBBLE;
42
+        $SectionsMargin		= isset($Format["SectionsMargin"]) ? $Format["SectionsMargin"] : 4;
43
+        $DrawLeftHead		= isset($Format["DrawLeftHead"]) ? $Format["DrawLeftHead"] : TRUE;
44
+        $DrawRightHead		= isset($Format["DrawRightHead"]) ? $Format["DrawRightHead"] : TRUE;
45
+        $HeadSize			= isset($Format["HeadSize"]) ? $Format["HeadSize"] : floor($Height/4);
46
+        $TextPadding		= isset($Format["TextPadding"]) ? $Format["TextPadding"] : 4;
47
+        $CaptionLayout		= isset($Format["CaptionLayout"]) ? $Format["CaptionLayout"] : INDICATOR_CAPTION_EXTENDED;
48
+        $CaptionPosition		= isset($Format["CaptionPosition"]) ? $Format["CaptionPosition"] : INDICATOR_CAPTION_INSIDE;
49
+        $CaptionColorFactor	= isset($Format["CaptionColorFactor"]) ? $Format["CaptionColorFactor"] : NULL;
50
+        $CaptionR			= isset($Format["CaptionR"]) ? $Format["CaptionR"] : 255;
51
+        $CaptionG			= isset($Format["CaptionG"]) ? $Format["CaptionG"] : 255;
52
+        $CaptionB			= isset($Format["CaptionB"]) ? $Format["CaptionB"] : 255;
53
+        $CaptionAlpha		= isset($Format["CaptionAlpha"]) ? $Format["CaptionAlpha"] : 100;
54
+        $SubCaptionColorFactor	= isset($Format["SubCaptionColorFactor"]) ? $Format["SubCaptionColorFactor"] : NULL;
55
+        $SubCaptionR		= isset($Format["SubCaptionR"]) ? $Format["SubCaptionR"] : 50;
56
+        $SubCaptionG		= isset($Format["SubCaptionG"]) ? $Format["SubCaptionG"] : 50;
57
+        $SubCaptionB		= isset($Format["SubCaptionB"]) ? $Format["SubCaptionB"] : 50;
58
+        $SubCaptionAlpha		= isset($Format["SubCaptionAlpha"]) ? $Format["SubCaptionAlpha"] : 100;
59
+        $ValueFontName		= isset($Format["ValueFontName"]) ? $Format["ValueFontName"] : $this->pChartObject->FontName;
60
+        $ValueFontSize		= isset($Format["ValueFontSize"]) ? $Format["ValueFontSize"] : $this->pChartObject->FontSize;
61
+        $CaptionFontName		= isset($Format["CaptionFontName"]) ? $Format["CaptionFontName"] : $this->pChartObject->FontName;
62
+        $CaptionFontSize		= isset($Format["CaptionFontSize"]) ? $Format["CaptionFontSize"] : $this->pChartObject->FontSize;
63
+        $Unit			= isset($Format["Unit"]) ? $Format["Unit"] : "";
64
+
65
+        /* Convert the Values to display to an array if needed */
66
+        if ( !is_array($Values) ) { $Value = $Values; $Values = ""; $Values[] = $Value; }
67
+
68
+        /* No section, let's die */
69
+        if ( $IndicatorSections == NULL ) { return(0); }
70
+
71
+        /* Determine indicator visual configuration */
72
+        $OverallMin = $IndicatorSections[0]["End"]; $OverallMax = $IndicatorSections[0]["Start"];
73
+        foreach ($IndicatorSections as $Key => $Settings)
74
+        {
75
+        if ( $Settings["End"] > $OverallMax )   { $OverallMax = $Settings["End"]; }
76
+        if ( $Settings["Start"] < $OverallMin ) { $OverallMin = $Settings["Start"]; }
77
+        }
78
+        $RealWidth = $Width - (count($IndicatorSections)-1)*$SectionsMargin;
79
+        $XScale    = $RealWidth / ($OverallMax-$OverallMin);
80
+
81
+        $X1 = $X; $ValuesPos = "";
82
+        foreach ($IndicatorSections as $Key => $Settings)
83
+        {
84
+        $Color      = array("R"=>$Settings["R"],"G"=>$Settings["G"],"B"=>$Settings["B"]);
85
+        $Caption    = $Settings["Caption"];
86
+        $SubCaption = $Settings["Start"]." - ".$Settings["End"];
87
+
88
+        $X2 = $X1 + ($Settings["End"] - $Settings["Start"]) * $XScale;
89
+
90
+        if ( $Key == 0 && $DrawLeftHead )
91 91
         {
92
-         $Poly = ""; $Poly[] = $X1-1; $Poly[] = $Y; $Poly[] = $X1-1; $Poly[] = $Y+$Height; $Poly[] = $X1-1-$HeadSize; $Poly[] = $Y+($Height/2);
93
-         $this->pChartObject->drawPolygon($Poly,$Color);
94
-         $this->pChartObject->drawLine($X1-2,$Y,$X1-2-$HeadSize,$Y+($Height/2),$Color);
95
-         $this->pChartObject->drawLine($X1-2,$Y+$Height,$X1-2-$HeadSize,$Y+($Height/2),$Color);
92
+            $Poly = ""; $Poly[] = $X1-1; $Poly[] = $Y; $Poly[] = $X1-1; $Poly[] = $Y+$Height; $Poly[] = $X1-1-$HeadSize; $Poly[] = $Y+($Height/2);
93
+            $this->pChartObject->drawPolygon($Poly,$Color);
94
+            $this->pChartObject->drawLine($X1-2,$Y,$X1-2-$HeadSize,$Y+($Height/2),$Color);
95
+            $this->pChartObject->drawLine($X1-2,$Y+$Height,$X1-2-$HeadSize,$Y+($Height/2),$Color);
96 96
         }
97 97
 
98
-       /* Determine the position of the breaks */
99
-       $Break = "";
100
-       foreach($Values as $iKey => $Value)
98
+        /* Determine the position of the breaks */
99
+        $Break = "";
100
+        foreach($Values as $iKey => $Value)
101 101
         {
102
-         if ( $Value >= $Settings["Start"] && $Value <= $Settings["End"] )
103
-          {
104
-           $XBreak  = $X1 + ($Value - $Settings["Start"]) * $XScale;
105
-           $ValuesPos[$Value] = $XBreak;
106
-           $Break[] = floor($XBreak);
107
-          }
102
+            if ( $Value >= $Settings["Start"] && $Value <= $Settings["End"] )
103
+            {
104
+            $XBreak  = $X1 + ($Value - $Settings["Start"]) * $XScale;
105
+            $ValuesPos[$Value] = $XBreak;
106
+            $Break[] = floor($XBreak);
107
+            }
108 108
         }
109 109
 
110
-       if ( $ValueDisplay == INDICATOR_VALUE_LABEL )
110
+        if ( $ValueDisplay == INDICATOR_VALUE_LABEL )
111 111
         {
112
-         if ( $Break == "" )
113
-          $this->pChartObject->drawFilledRectangle($X1,$Y,$X2,$Y+$Height,$Color);
114
-         else
115
-          {
116
-           sort($Break);
117
-           $Poly = ""; $Poly[] = $X1; $Poly[] = $Y; $LastPointWritten = FALSE;
118
-           foreach($Break as $iKey => $Value)
112
+            if ( $Break == "" )
113
+            $this->pChartObject->drawFilledRectangle($X1,$Y,$X2,$Y+$Height,$Color);
114
+            else
115
+            {
116
+            sort($Break);
117
+            $Poly = ""; $Poly[] = $X1; $Poly[] = $Y; $LastPointWritten = FALSE;
118
+            foreach($Break as $iKey => $Value)
119 119
             {
120
-             if ( $Value-5 >= $X1 )
121
-              { $Poly[] = $Value-5; $Poly[] = $Y; }
122
-             elseif ($X1 - ($Value-5) > 0 )
123
-              {
124
-               $Offset = $X1 - ($Value-5);
125
-               $Poly = ""; $Poly[] = $X1; $Poly[] = $Y + $Offset;
126
-              }
127
-
128
-             $Poly[] = $Value;   $Poly[] = $Y+5;
129
-
130
-             if ( $Value+5 <= $X2 )
131
-              { $Poly[] = $Value+5; $Poly[] = $Y; }
132
-             elseif (($Value+5) > $X2 )
133
-              {
134
-               $Offset = ($Value+5) - $X2;
135
-               $Poly[] = $X2; $Poly[] = $Y + $Offset;
136
-               $LastPointWritten = TRUE;
137
-              }
120
+                if ( $Value-5 >= $X1 )
121
+                { $Poly[] = $Value-5; $Poly[] = $Y; }
122
+                elseif ($X1 - ($Value-5) > 0 )
123
+                {
124
+                $Offset = $X1 - ($Value-5);
125
+                $Poly = ""; $Poly[] = $X1; $Poly[] = $Y + $Offset;
126
+                }
127
+
128
+                $Poly[] = $Value;   $Poly[] = $Y+5;
129
+
130
+                if ( $Value+5 <= $X2 )
131
+                { $Poly[] = $Value+5; $Poly[] = $Y; }
132
+                elseif (($Value+5) > $X2 )
133
+                {
134
+                $Offset = ($Value+5) - $X2;
135
+                $Poly[] = $X2; $Poly[] = $Y + $Offset;
136
+                $LastPointWritten = TRUE;
137
+                }
138 138
 
139 139
             }
140
-           if ( !$LastPointWritten ) { $Poly[] = $X2; $Poly[] = $Y; }
141
-           $Poly[] = $X2; $Poly[] = $Y+$Height;
142
-           $Poly[] = $X1; $Poly[] = $Y+$Height;
140
+            if ( !$LastPointWritten ) { $Poly[] = $X2; $Poly[] = $Y; }
141
+            $Poly[] = $X2; $Poly[] = $Y+$Height;
142
+            $Poly[] = $X1; $Poly[] = $Y+$Height;
143 143
 
144
-           $this->pChartObject->drawPolygon($Poly,$Color);
145
-          }
144
+            $this->pChartObject->drawPolygon($Poly,$Color);
145
+            }
146 146
         }
147
-       else
147
+        else
148 148
         $this->pChartObject->drawFilledRectangle($X1,$Y,$X2,$Y+$Height,$Color);
149 149
 
150
-       if ( $Key == count($IndicatorSections)-1 && $DrawRightHead )
150
+        if ( $Key == count($IndicatorSections)-1 && $DrawRightHead )
151 151
         {
152
-         $Poly = ""; $Poly[] = $X2+1; $Poly[] = $Y; $Poly[] = $X2+1; $Poly[] = $Y+$Height; $Poly[] = $X2+1+$HeadSize; $Poly[] = $Y+($Height/2);
153
-         $this->pChartObject->drawPolygon($Poly,$Color);
154
-         $this->pChartObject->drawLine($X2+1,$Y,$X2+1+$HeadSize,$Y+($Height/2),$Color);
155
-         $this->pChartObject->drawLine($X2+1,$Y+$Height,$X2+1+$HeadSize,$Y+($Height/2),$Color);
152
+            $Poly = ""; $Poly[] = $X2+1; $Poly[] = $Y; $Poly[] = $X2+1; $Poly[] = $Y+$Height; $Poly[] = $X2+1+$HeadSize; $Poly[] = $Y+($Height/2);
153
+            $this->pChartObject->drawPolygon($Poly,$Color);
154
+            $this->pChartObject->drawLine($X2+1,$Y,$X2+1+$HeadSize,$Y+($Height/2),$Color);
155
+            $this->pChartObject->drawLine($X2+1,$Y+$Height,$X2+1+$HeadSize,$Y+($Height/2),$Color);
156 156
         }
157 157
 
158
-       if ( $CaptionPosition == INDICATOR_CAPTION_INSIDE )
158
+        if ( $CaptionPosition == INDICATOR_CAPTION_INSIDE )
159 159
         {
160
-         $TxtPos  = $this->pChartObject->getTextBox($X1,$Y+$Height+$TextPadding,$CaptionFontName,$CaptionFontSize,0,$Caption);
161
-         $YOffset = ($TxtPos[0]["Y"] - $TxtPos[2]["Y"]) + $TextPadding;
160
+            $TxtPos  = $this->pChartObject->getTextBox($X1,$Y+$Height+$TextPadding,$CaptionFontName,$CaptionFontSize,0,$Caption);
161
+            $YOffset = ($TxtPos[0]["Y"] - $TxtPos[2]["Y"]) + $TextPadding;
162 162
 
163
-         if ( $CaptionLayout == INDICATOR_CAPTION_EXTENDED )
164
-          {
165
-           $TxtPos  = $this->pChartObject->getTextBox($X1,$Y+$Height+$TextPadding,$CaptionFontName,$CaptionFontSize,0,$SubCaption);
166
-           $YOffset = $YOffset + ($TxtPos[0]["Y"] - $TxtPos[2]["Y"]) + $TextPadding*2;
167
-          }
163
+            if ( $CaptionLayout == INDICATOR_CAPTION_EXTENDED )
164
+            {
165
+            $TxtPos  = $this->pChartObject->getTextBox($X1,$Y+$Height+$TextPadding,$CaptionFontName,$CaptionFontSize,0,$SubCaption);
166
+            $YOffset = $YOffset + ($TxtPos[0]["Y"] - $TxtPos[2]["Y"]) + $TextPadding*2;
167
+            }
168 168
 
169
-         $XOffset = $TextPadding;
169
+            $XOffset = $TextPadding;
170 170
         }
171
-       else
171
+        else
172 172
         { $YOffset = 0; $XOffset = 0; }
173 173
 
174
-       if ( $CaptionColorFactor == NULL )
174
+        if ( $CaptionColorFactor == NULL )
175 175
         { $CaptionColor    = array("Align"=>TEXT_ALIGN_TOPLEFT,"FontName"=>$CaptionFontName,"FontSize"=>$CaptionFontSize,"R"=>$CaptionR,"G"=>$CaptionG,"B"=>$CaptionB,"Alpha"=>$CaptionAlpha); }
176
-       else
176
+        else
177 177
         { $CaptionColor    = array("Align"=>TEXT_ALIGN_TOPLEFT,"FontName"=>$CaptionFontName,"FontSize"=>$CaptionFontSize,"R"=>$Settings["R"]+$CaptionColorFactor,"G"=>$Settings["G"]+$CaptionColorFactor,"B"=>$Settings["B"]+$CaptionColorFactor); }
178 178
 
179
-       if ( $SubCaptionColorFactor == NULL )
179
+        if ( $SubCaptionColorFactor == NULL )
180 180
         $SubCaptionColor = array("Align"=>TEXT_ALIGN_TOPLEFT,"FontName"=>$CaptionFontName,"FontSize"=>$CaptionFontSize,"R"=>$SubCaptionR,"G"=>$SubCaptionG,"B"=>$SubCaptionB,"Alpha"=>$SubCaptionAlpha);
181
-       else
181
+        else
182 182
         $SubCaptionColor = array("Align"=>TEXT_ALIGN_TOPLEFT,"FontName"=>$CaptionFontName,"FontSize"=>$CaptionFontSize,"R"=>$Settings["R"]+$SubCaptionColorFactor,"G"=>$Settings["G"]+$SubCaptionColorFactor,"B"=>$Settings["B"]+$SubCaptionColorFactor);
183 183
 
184
-       $RestoreShadow = $this->pChartObject->Shadow;
185
-       $this->pChartObject->Shadow = FALSE;
184
+        $RestoreShadow = $this->pChartObject->Shadow;
185
+        $this->pChartObject->Shadow = FALSE;
186 186
 
187
-       if ( $CaptionLayout == INDICATOR_CAPTION_DEFAULT )
187
+        if ( $CaptionLayout == INDICATOR_CAPTION_DEFAULT )
188 188
         $this->pChartObject->drawText($X1,$Y+$Height+$TextPadding,$Caption,$CaptionColor);
189
-       elseif ( $CaptionLayout == INDICATOR_CAPTION_EXTENDED )
189
+        elseif ( $CaptionLayout == INDICATOR_CAPTION_EXTENDED )
190 190
         {
191
-         $TxtPos        = $this->pChartObject->getTextBox($X1,$Y+$Height+$TextPadding,$CaptionFontName,$CaptionFontSize,0,$Caption);
192
-         $CaptionHeight = $TxtPos[0]["Y"] - $TxtPos[2]["Y"];
191
+            $TxtPos        = $this->pChartObject->getTextBox($X1,$Y+$Height+$TextPadding,$CaptionFontName,$CaptionFontSize,0,$Caption);
192
+            $CaptionHeight = $TxtPos[0]["Y"] - $TxtPos[2]["Y"];
193 193
 
194
-         $this->pChartObject->drawText($X1+$XOffset,$Y+$Height-$YOffset+$TextPadding,$Caption,$CaptionColor);
195
-         $this->pChartObject->drawText($X1+$XOffset,$Y+$Height-$YOffset+$CaptionHeight+$TextPadding*2,$SubCaption,$SubCaptionColor);
194
+            $this->pChartObject->drawText($X1+$XOffset,$Y+$Height-$YOffset+$TextPadding,$Caption,$CaptionColor);
195
+            $this->pChartObject->drawText($X1+$XOffset,$Y+$Height-$YOffset+$CaptionHeight+$TextPadding*2,$SubCaption,$SubCaptionColor);
196 196
         }
197 197
 
198
-       $this->pChartObject->Shadow = $RestoreShadow;
198
+        $this->pChartObject->Shadow = $RestoreShadow;
199 199
 
200
-       $X1 = $X2 + $SectionsMargin;
201
-      }
200
+        $X1 = $X2 + $SectionsMargin;
201
+        }
202 202
 
203
-     $RestoreShadow = $this->pChartObject->Shadow;
204
-     $this->pChartObject->Shadow = FALSE;
203
+        $RestoreShadow = $this->pChartObject->Shadow;
204
+        $this->pChartObject->Shadow = FALSE;
205 205
 
206
-     foreach($Values as $Key => $Value)
207
-      {
208
-       if ( $Value >= $OverallMin && $Value <= $OverallMax )
206
+        foreach($Values as $Key => $Value)
207
+        {
208
+        if ( $Value >= $OverallMin && $Value <= $OverallMax )
209 209
         {
210
-         foreach ($IndicatorSections as $Key => $Settings)
211
-          {
212
-           if ( $Value >= $Settings["Start"] && $Value <= $Settings["End"] )
210
+            foreach ($IndicatorSections as $Key => $Settings)
213 211
             {
214
-             $X1 = $ValuesPos[$Value]; //$X + $Key*$SectionsMargin + ($Value - $OverallMin) * $XScale;
215
-
216
-             if ( $ValueDisplay == INDICATOR_VALUE_BUBBLE )
217
-              {
218
-               $TxtPos = $this->pChartObject->getTextBox($X1,$Y,$ValueFontName,$ValueFontSize,0,$Value.$Unit);
219
-               $Radius = floor(($TxtPos[1]["X"] - $TxtPos[0]["X"] + $TextPadding*4)/2);
220
-
221
-               $this->pChartObject->drawFilledCircle($X1,$Y,$Radius+4,array("R"=>$Settings["R"]+20,"G"=>$Settings["G"]+20,"B"=>$Settings["B"]+20));
222
-               $this->pChartObject->drawFilledCircle($X1,$Y,$Radius,array("R"=>255,"G"=>255,"B"=>255));
223
-
224
-               $TextSettings = array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontName"=>$ValueFontName,"FontSize"=>$ValueFontSize);
225
-               $this->pChartObject->drawText($X1-1,$Y-1,$Value.$Unit,$TextSettings);
226
-              }
227
-             elseif( $ValueDisplay == INDICATOR_VALUE_LABEL )
228
-              {
229
-               $Caption = "";
230
-               $Caption[] = array("Format"=>array("R"=>$Settings["R"],"G"=>$Settings["G"],"B"=>$Settings["B"],"Alpha"=>100),"Caption"=>$Value.$Unit);
231
-               $this->pChartObject->drawLabelBox(floor($X1),floor($Y)+2,"Value - ".$Settings["Caption"],$Caption);
232
-              }
212
+            if ( $Value >= $Settings["Start"] && $Value <= $Settings["End"] )
213
+            {
214
+                $X1 = $ValuesPos[$Value]; //$X + $Key*$SectionsMargin + ($Value - $OverallMin) * $XScale;
215
+
216
+                if ( $ValueDisplay == INDICATOR_VALUE_BUBBLE )
217
+                {
218
+                $TxtPos = $this->pChartObject->getTextBox($X1,$Y,$ValueFontName,$ValueFontSize,0,$Value.$Unit);
219
+                $Radius = floor(($TxtPos[1]["X"] - $TxtPos[0]["X"] + $TextPadding*4)/2);
220
+
221
+                $this->pChartObject->drawFilledCircle($X1,$Y,$Radius+4,array("R"=>$Settings["R"]+20,"G"=>$Settings["G"]+20,"B"=>$Settings["B"]+20));
222
+                $this->pChartObject->drawFilledCircle($X1,$Y,$Radius,array("R"=>255,"G"=>255,"B"=>255));
223
+
224
+                $TextSettings = array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontName"=>$ValueFontName,"FontSize"=>$ValueFontSize);
225
+                $this->pChartObject->drawText($X1-1,$Y-1,$Value.$Unit,$TextSettings);
226
+                }
227
+                elseif( $ValueDisplay == INDICATOR_VALUE_LABEL )
228
+                {
229
+                $Caption = "";
230
+                $Caption[] = array("Format"=>array("R"=>$Settings["R"],"G"=>$Settings["G"],"B"=>$Settings["B"],"Alpha"=>100),"Caption"=>$Value.$Unit);
231
+                $this->pChartObject->drawLabelBox(floor($X1),floor($Y)+2,"Value - ".$Settings["Caption"],$Caption);
232
+                }
233
+            }
234
+            $X1 = $X2 + $SectionsMargin;
233 235
             }
234
-           $X1 = $X2 + $SectionsMargin;
235
-          }
236 236
         }
237
-      }
238
-     $this->pChartObject->Shadow = $RestoreShadow;
237
+        }
238
+        $this->pChartObject->Shadow = $RestoreShadow;
239
+    }
239 240
     }
240
-  }
241 241
 ?>
242 242
\ No newline at end of file
Please login to merge, or discard this patch.
default/boinc/modules/boincstats/includes/pchart/class/pSpring.class.php 1 patch
Indentation   +665 added lines, -665 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
- /*
2
+    /*
3 3
      pSpring - class to draw spring graphs
4 4
 
5 5
      Version     : 2.1.3
@@ -13,856 +13,856 @@  discard block
 block discarded – undo
13 13
      You can find the whole class documentation on the pChart web site.
14 14
  */
15 15
 
16
- define("NODE_TYPE_FREE"	, 690001);
17
- define("NODE_TYPE_CENTRAL"	, 690002);
18
-
19
- define("NODE_SHAPE_CIRCLE"	, 690011);
20
- define("NODE_SHAPE_TRIANGLE"	, 690012);
21
- define("NODE_SHAPE_SQUARE"	, 690013);
22
-
23
- define("ALGORITHM_RANDOM"	, 690021);
24
- define("ALGORITHM_WEIGHTED"	, 690022);
25
- define("ALGORITHM_CIRCULAR"	, 690023);
26
- define("ALGORITHM_CENTRAL"	, 690024);
27
-
28
- define("LABEL_CLASSIC"		, 690031);
29
- define("LABEL_LIGHT"		, 690032);
30
-
31
- /* pSpring class definition */
32
- class pSpring
33
-  {
34
-   var $History;
35
-   var $pChartObject;
36
-   var $Data;
37
-   var $Links;
38
-   var $X1;
39
-   var $Y1;
40
-   var $X2;
41
-   var $Y2;
42
-   var $AutoComputeFreeZone;
43
-   var $Labels;
44
-
45
-   /* Class creator */
46
-   function pSpring()
16
+    define("NODE_TYPE_FREE"	, 690001);
17
+    define("NODE_TYPE_CENTRAL"	, 690002);
18
+
19
+    define("NODE_SHAPE_CIRCLE"	, 690011);
20
+    define("NODE_SHAPE_TRIANGLE"	, 690012);
21
+    define("NODE_SHAPE_SQUARE"	, 690013);
22
+
23
+    define("ALGORITHM_RANDOM"	, 690021);
24
+    define("ALGORITHM_WEIGHTED"	, 690022);
25
+    define("ALGORITHM_CIRCULAR"	, 690023);
26
+    define("ALGORITHM_CENTRAL"	, 690024);
27
+
28
+    define("LABEL_CLASSIC"		, 690031);
29
+    define("LABEL_LIGHT"		, 690032);
30
+
31
+    /* pSpring class definition */
32
+    class pSpring
47 33
     {
48
-     /* Initialise data arrays */
49
-     $this->Data = "";
50
-     $this->Links = "";
51
-
52
-     /* Set nodes defaults */
53
-     $this->Default["R"]		= 255;
54
-     $this->Default["G"]		= 255;
55
-     $this->Default["B"]		= 255;
56
-     $this->Default["Alpha"]		= 100;
57
-     $this->Default["BorderR"]		= 0;
58
-     $this->Default["BorderG"]		= 0;
59
-     $this->Default["BorderB"]		= 0;
60
-     $this->Default["BorderAlpha"]	= 100;
61
-     $this->Default["Surrounding"]	= NULL;
62
-     $this->Default["BackgroundR"]	= 255;
63
-     $this->Default["BackgroundG"]	= 255;
64
-     $this->Default["BackgroundB"]	= 255;
65
-     $this->Default["BackgroundAlpha"]	= 0;
66
-     $this->Default["Force"]		= 1;
67
-     $this->Default["NodeType"]		= NODE_TYPE_FREE;
68
-     $this->Default["Size"]		= 5;
69
-     $this->Default["Shape"]		= NODE_SHAPE_CIRCLE;
70
-     $this->Default["FreeZone"]		= 40;
71
-     $this->Default["LinkR"]		= 0;
72
-     $this->Default["LinkG"]		= 0;
73
-     $this->Default["LinkB"]		= 0;
74
-     $this->Default["LinkAlpha"]	= 0;
75
-
76
-     $this->Labels["Type"]		= LABEL_CLASSIC;
77
-     $this->Labels["R"]			= 0;
78
-     $this->Labels["G"]			= 0;
79
-     $this->Labels["B"]			= 0;
80
-     $this->Labels["Alpha"]		= 100;
81
-
82
-     $this->AutoComputeFreeZone         = FALSE;
34
+    var $History;
35
+    var $pChartObject;
36
+    var $Data;
37
+    var $Links;
38
+    var $X1;
39
+    var $Y1;
40
+    var $X2;
41
+    var $Y2;
42
+    var $AutoComputeFreeZone;
43
+    var $Labels;
44
+
45
+    /* Class creator */
46
+    function pSpring()
47
+    {
48
+        /* Initialise data arrays */
49
+        $this->Data = "";
50
+        $this->Links = "";
51
+
52
+        /* Set nodes defaults */
53
+        $this->Default["R"]		= 255;
54
+        $this->Default["G"]		= 255;
55
+        $this->Default["B"]		= 255;
56
+        $this->Default["Alpha"]		= 100;
57
+        $this->Default["BorderR"]		= 0;
58
+        $this->Default["BorderG"]		= 0;
59
+        $this->Default["BorderB"]		= 0;
60
+        $this->Default["BorderAlpha"]	= 100;
61
+        $this->Default["Surrounding"]	= NULL;
62
+        $this->Default["BackgroundR"]	= 255;
63
+        $this->Default["BackgroundG"]	= 255;
64
+        $this->Default["BackgroundB"]	= 255;
65
+        $this->Default["BackgroundAlpha"]	= 0;
66
+        $this->Default["Force"]		= 1;
67
+        $this->Default["NodeType"]		= NODE_TYPE_FREE;
68
+        $this->Default["Size"]		= 5;
69
+        $this->Default["Shape"]		= NODE_SHAPE_CIRCLE;
70
+        $this->Default["FreeZone"]		= 40;
71
+        $this->Default["LinkR"]		= 0;
72
+        $this->Default["LinkG"]		= 0;
73
+        $this->Default["LinkB"]		= 0;
74
+        $this->Default["LinkAlpha"]	= 0;
75
+
76
+        $this->Labels["Type"]		= LABEL_CLASSIC;
77
+        $this->Labels["R"]			= 0;
78
+        $this->Labels["G"]			= 0;
79
+        $this->Labels["B"]			= 0;
80
+        $this->Labels["Alpha"]		= 100;
81
+
82
+        $this->AutoComputeFreeZone         = FALSE;
83 83
     }
84 84
 
85
-   /* Set default links options */
86
-   function setLinkDefaults($Settings="")
85
+    /* Set default links options */
86
+    function setLinkDefaults($Settings="")
87 87
     {
88
-     if ( isset($Settings["R"]) )     { $this->Default["LinkR"] = $Settings["R"]; }
89
-     if ( isset($Settings["G"]) )     { $this->Default["LinkG"] = $Settings["G"]; }
90
-     if ( isset($Settings["B"]) )     { $this->Default["LinkB"] = $Settings["B"]; }
91
-     if ( isset($Settings["Alpha"]) ) { $this->Default["LinkAlpha"] = $Settings["Alpha"]; }
88
+        if ( isset($Settings["R"]) )     { $this->Default["LinkR"] = $Settings["R"]; }
89
+        if ( isset($Settings["G"]) )     { $this->Default["LinkG"] = $Settings["G"]; }
90
+        if ( isset($Settings["B"]) )     { $this->Default["LinkB"] = $Settings["B"]; }
91
+        if ( isset($Settings["Alpha"]) ) { $this->Default["LinkAlpha"] = $Settings["Alpha"]; }
92 92
     }
93 93
 
94
-   /* Set default links options */
95
-   function setLabelsSettings($Settings="")
94
+    /* Set default links options */
95
+    function setLabelsSettings($Settings="")
96 96
     {
97
-     if ( isset($Settings["Type"]) )  { $this->Labels["Type"] = $Settings["Type"]; }
98
-     if ( isset($Settings["R"]) )     { $this->Labels["R"] = $Settings["R"]; }
99
-     if ( isset($Settings["G"]) )     { $this->Labels["G"] = $Settings["G"]; }
100
-     if ( isset($Settings["B"]) )     { $this->Labels["B"] = $Settings["B"]; }
101
-     if ( isset($Settings["Alpha"]) ) { $this->Labels["Alpha"] = $Settings["Alpha"]; }
97
+        if ( isset($Settings["Type"]) )  { $this->Labels["Type"] = $Settings["Type"]; }
98
+        if ( isset($Settings["R"]) )     { $this->Labels["R"] = $Settings["R"]; }
99
+        if ( isset($Settings["G"]) )     { $this->Labels["G"] = $Settings["G"]; }
100
+        if ( isset($Settings["B"]) )     { $this->Labels["B"] = $Settings["B"]; }
101
+        if ( isset($Settings["Alpha"]) ) { $this->Labels["Alpha"] = $Settings["Alpha"]; }
102 102
     }
103 103
 
104
-   /* Auto compute the FreeZone size based on the number of connections */
105
-   function autoFreeZone()
104
+    /* Auto compute the FreeZone size based on the number of connections */
105
+    function autoFreeZone()
106 106
     {
107
-     /* Check connections reciprocity */
108
-     foreach($this->Data as $Key => $Settings)
109
-      {
110
-       if ( isset($Settings["Connections"]) )
107
+        /* Check connections reciprocity */
108
+        foreach($this->Data as $Key => $Settings)
109
+        {
110
+        if ( isset($Settings["Connections"]) )
111 111
         { $this->Data[$Key]["FreeZone"] = count($Settings["Connections"])*10 + 20; }
112
-       else
112
+        else
113 113
         { $this->Data[$Key]["FreeZone"] = 20; }
114
-      }
114
+        }
115 115
 
116 116
     }
117 117
 
118
-   /* Set link properties */
119
-   function linkProperties($FromNode,$ToNode,$Settings)
118
+    /* Set link properties */
119
+    function linkProperties($FromNode,$ToNode,$Settings)
120 120
     {
121
-     if ( !isset($this->Data[$FromNode]) ) { return(0); }
122
-     if ( !isset($this->Data[$ToNode]) )   { return(0); }
123
-
124
-     $R			= isset($Settings["R"]) ? $Settings["R"] : 0;
125
-     $G			= isset($Settings["G"]) ? $Settings["G"] : 0;
126
-     $B			= isset($Settings["B"]) ? $Settings["B"] : 0;
127
-     $Alpha		= isset($Settings["Alpha"]) ? $Settings["Alpha"] : 100;
128
-     $Name		= isset($Settings["Name"]) ? $Settings["Name"] : NULL;
129
-     $Ticks		= isset($Settings["Ticks"]) ? $Settings["Ticks"] : NULL;
130
-
131
-     $this->Links[$FromNode][$ToNode]["R"] = $R;         $this->Links[$ToNode][$FromNode]["R"] = $R;
132
-     $this->Links[$FromNode][$ToNode]["G"] = $G;         $this->Links[$ToNode][$FromNode]["G"] = $G;
133
-     $this->Links[$FromNode][$ToNode]["B"] = $B;         $this->Links[$ToNode][$FromNode]["B"] = $B;
134
-     $this->Links[$FromNode][$ToNode]["Alpha"] = $Alpha; $this->Links[$ToNode][$FromNode]["Alpha"] = $Alpha;
135
-     $this->Links[$FromNode][$ToNode]["Name"] = $Name;   $this->Links[$ToNode][$FromNode]["Name"] = $Name;
136
-     $this->Links[$FromNode][$ToNode]["Ticks"] = $Ticks; $this->Links[$ToNode][$FromNode]["Ticks"] = $Ticks;
121
+        if ( !isset($this->Data[$FromNode]) ) { return(0); }
122
+        if ( !isset($this->Data[$ToNode]) )   { return(0); }
123
+
124
+        $R			= isset($Settings["R"]) ? $Settings["R"] : 0;
125
+        $G			= isset($Settings["G"]) ? $Settings["G"] : 0;
126
+        $B			= isset($Settings["B"]) ? $Settings["B"] : 0;
127
+        $Alpha		= isset($Settings["Alpha"]) ? $Settings["Alpha"] : 100;
128
+        $Name		= isset($Settings["Name"]) ? $Settings["Name"] : NULL;
129
+        $Ticks		= isset($Settings["Ticks"]) ? $Settings["Ticks"] : NULL;
130
+
131
+        $this->Links[$FromNode][$ToNode]["R"] = $R;         $this->Links[$ToNode][$FromNode]["R"] = $R;
132
+        $this->Links[$FromNode][$ToNode]["G"] = $G;         $this->Links[$ToNode][$FromNode]["G"] = $G;
133
+        $this->Links[$FromNode][$ToNode]["B"] = $B;         $this->Links[$ToNode][$FromNode]["B"] = $B;
134
+        $this->Links[$FromNode][$ToNode]["Alpha"] = $Alpha; $this->Links[$ToNode][$FromNode]["Alpha"] = $Alpha;
135
+        $this->Links[$FromNode][$ToNode]["Name"] = $Name;   $this->Links[$ToNode][$FromNode]["Name"] = $Name;
136
+        $this->Links[$FromNode][$ToNode]["Ticks"] = $Ticks; $this->Links[$ToNode][$FromNode]["Ticks"] = $Ticks;
137 137
     }
138 138
 
139
-   function setNodeDefaults($Settings="")
139
+    function setNodeDefaults($Settings="")
140 140
     {
141
-     if ( isset($Settings["R"]) ) { $this->Default["R"]					= $Settings["R"]; }
142
-     if ( isset($Settings["G"]) ) { $this->Default["G"]					= $Settings["G"]; }
143
-     if ( isset($Settings["B"]) ) { $this->Default["B"]					= $Settings["B"]; }
144
-     if ( isset($Settings["Alpha"]) ) { $this->Default["Alpha"]				= $Settings["Alpha"]; }
145
-     if ( isset($Settings["BorderR"]) ) { $this->Default["BorderR"]			= $Settings["BorderR"]; }
146
-     if ( isset($Settings["BorderG"]) ) { $this->Default["BorderG"]			= $Settings["BorderG"]; }
147
-     if ( isset($Settings["BorderB"]) ) { $this->Default["BorderB"]			= $Settings["BorderB"]; }
148
-     if ( isset($Settings["BorderAlpha"]) ) { $this->Default["BorderAlpha"]		= $Settings["BorderAlpha"]; }
149
-     if ( isset($Settings["Surrounding"]) ) { $this->Default["Surrounding"]		= $Settings["Surrounding"]; }
150
-     if ( isset($Settings["BackgroundR"]) ) { $this->Default["BackgroundR"]		= $Settings["BackgroundR"]; }
151
-     if ( isset($Settings["BackgroundG"]) ) { $this->Default["BackgroundG"]		= $Settings["BackgroundG"]; }
152
-     if ( isset($Settings["BackgroundB"]) ) { $this->Default["BackgroundB"]		= $Settings["BackgroundB"]; }
153
-     if ( isset($Settings["BackgroundAlpha"]) ) { $this->Default["BackgroundAlpha"]	= $Settings["BackgroundAlpha"]; }
154
-     if ( isset($Settings["NodeType"]) ) { $this->Default["NodeType"]			= $Settings["NodeType"]; }
155
-     if ( isset($Settings["Size"]) ) { $this->Default["Size"]				= $Settings["Size"]; }
156
-     if ( isset($Settings["Shape"]) ) { $this->Default["Shape"]				= $Settings["Shape"]; }
157
-     if ( isset($Settings["FreeZone"]) ) { $this->Default["FreeZone"]			= $Settings["FreeZone"]; }
141
+        if ( isset($Settings["R"]) ) { $this->Default["R"]					= $Settings["R"]; }
142
+        if ( isset($Settings["G"]) ) { $this->Default["G"]					= $Settings["G"]; }
143
+        if ( isset($Settings["B"]) ) { $this->Default["B"]					= $Settings["B"]; }
144
+        if ( isset($Settings["Alpha"]) ) { $this->Default["Alpha"]				= $Settings["Alpha"]; }
145
+        if ( isset($Settings["BorderR"]) ) { $this->Default["BorderR"]			= $Settings["BorderR"]; }
146
+        if ( isset($Settings["BorderG"]) ) { $this->Default["BorderG"]			= $Settings["BorderG"]; }
147
+        if ( isset($Settings["BorderB"]) ) { $this->Default["BorderB"]			= $Settings["BorderB"]; }
148
+        if ( isset($Settings["BorderAlpha"]) ) { $this->Default["BorderAlpha"]		= $Settings["BorderAlpha"]; }
149
+        if ( isset($Settings["Surrounding"]) ) { $this->Default["Surrounding"]		= $Settings["Surrounding"]; }
150
+        if ( isset($Settings["BackgroundR"]) ) { $this->Default["BackgroundR"]		= $Settings["BackgroundR"]; }
151
+        if ( isset($Settings["BackgroundG"]) ) { $this->Default["BackgroundG"]		= $Settings["BackgroundG"]; }
152
+        if ( isset($Settings["BackgroundB"]) ) { $this->Default["BackgroundB"]		= $Settings["BackgroundB"]; }
153
+        if ( isset($Settings["BackgroundAlpha"]) ) { $this->Default["BackgroundAlpha"]	= $Settings["BackgroundAlpha"]; }
154
+        if ( isset($Settings["NodeType"]) ) { $this->Default["NodeType"]			= $Settings["NodeType"]; }
155
+        if ( isset($Settings["Size"]) ) { $this->Default["Size"]				= $Settings["Size"]; }
156
+        if ( isset($Settings["Shape"]) ) { $this->Default["Shape"]				= $Settings["Shape"]; }
157
+        if ( isset($Settings["FreeZone"]) ) { $this->Default["FreeZone"]			= $Settings["FreeZone"]; }
158 158
     }
159 159
 
160
-   /* Add a node */
161
-   function addNode($NodeID,$Settings="")
160
+    /* Add a node */
161
+    function addNode($NodeID,$Settings="")
162 162
     {
163
-     /* if the node already exists, ignore */
164
-     if (isset($this->Data[$NodeID])) { return(0); }
165
-
166
-     $Name		= isset($Settings["Name"]) ? $Settings["Name"] : "Node ".$NodeID;
167
-     $Connections	= isset($Settings["Connections"]) ? $Settings["Connections"] : NULL;
168
-
169
-     $R			= isset($Settings["R"]) ? $Settings["R"] : $this->Default["R"];
170
-     $G			= isset($Settings["G"]) ? $Settings["G"] : $this->Default["G"];
171
-     $B			= isset($Settings["B"]) ? $Settings["B"] : $this->Default["B"];
172
-     $Alpha		= isset($Settings["Alpha"]) ? $Settings["Alpha"] : $this->Default["Alpha"];
173
-     $BorderR		= isset($Settings["BorderR"]) ? $Settings["BorderR"] : $this->Default["BorderR"];
174
-     $BorderG		= isset($Settings["BorderG"]) ? $Settings["BorderG"] : $this->Default["BorderG"];
175
-     $BorderB		= isset($Settings["BorderB"]) ? $Settings["BorderB"] : $this->Default["BorderB"];
176
-     $BorderAlpha	= isset($Settings["BorderAlpha"]) ? $Settings["BorderAlpha"] : $this->Default["BorderAlpha"];
177
-     $Surrounding	= isset($Settings["Surrounding"]) ? $Settings["Surrounding"] : $this->Default["Surrounding"];
178
-     $BackgroundR	= isset($Settings["BackgroundR"]) ? $Settings["BackgroundR"] : $this->Default["BackgroundR"];
179
-     $BackgroundG	= isset($Settings["BackgroundG"]) ? $Settings["BackgroundG"] : $this->Default["BackgroundG"];
180
-     $BackgroundB	= isset($Settings["BackgroundB"]) ? $Settings["BackgroundB"] : $this->Default["BackgroundB"];
181
-     $BackgroundAlpha	= isset($Settings["BackgroundAlpha"]) ? $Settings["BackgroundAlpha"] : $this->Default["BackgroundAlpha"];
182
-     $Force		= isset($Settings["Force"]) ? $Settings["Force"] :  $this->Default["Force"];
183
-     $NodeType		= isset($Settings["NodeType"]) ? $Settings["NodeType"] : $this->Default["NodeType"];
184
-     $Size		= isset($Settings["Size"]) ? $Settings["Size"] : $this->Default["Size"];
185
-     $Shape		= isset($Settings["Shape"]) ? $Settings["Shape"] : $this->Default["Shape"];
186
-     $FreeZone		= isset($Settings["FreeZone"]) ? $Settings["FreeZone"] : $this->Default["FreeZone"];
187
-
188
-     if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; }
189
-
190
-     $this->Data[$NodeID]["R"] = $R; $this->Data[$NodeID]["G"] = $G; $this->Data[$NodeID]["B"] = $B; $this->Data[$NodeID]["Alpha"] = $Alpha;
191
-     $this->Data[$NodeID]["BorderR"] = $BorderR; $this->Data[$NodeID]["BorderG"] = $BorderG; $this->Data[$NodeID]["BorderB"] = $BorderB; $this->Data[$NodeID]["BorderAlpha"] = $BorderAlpha;
192
-     $this->Data[$NodeID]["BackgroundR"]	= $BackgroundR; $this->Data[$NodeID]["BackgroundG"] = $BackgroundG; $this->Data[$NodeID]["BackgroundB"] = $BackgroundB; $this->Data[$NodeID]["BackgroundAlpha"] = $BackgroundAlpha;
193
-     $this->Data[$NodeID]["Name"]		= $Name;
194
-     $this->Data[$NodeID]["Force"]		= $Force;
195
-     $this->Data[$NodeID]["Type"]		= $NodeType;
196
-     $this->Data[$NodeID]["Size"]		= $Size;
197
-     $this->Data[$NodeID]["Shape"]		= $Shape;
198
-     $this->Data[$NodeID]["FreeZone"]		= $FreeZone;
199
-     if ( $Connections != NULL )
200
-      {
201
-       if ( is_array($Connections ) )
202
-        {
203
-         foreach($Connections as $Key => $Value)
204
-          $this->Data[$NodeID]["Connections"][] = $Value;
205
-        }
206
-       else
163
+        /* if the node already exists, ignore */
164
+        if (isset($this->Data[$NodeID])) { return(0); }
165
+
166
+        $Name		= isset($Settings["Name"]) ? $Settings["Name"] : "Node ".$NodeID;
167
+        $Connections	= isset($Settings["Connections"]) ? $Settings["Connections"] : NULL;
168
+
169
+        $R			= isset($Settings["R"]) ? $Settings["R"] : $this->Default["R"];
170
+        $G			= isset($Settings["G"]) ? $Settings["G"] : $this->Default["G"];
171
+        $B			= isset($Settings["B"]) ? $Settings["B"] : $this->Default["B"];
172
+        $Alpha		= isset($Settings["Alpha"]) ? $Settings["Alpha"] : $this->Default["Alpha"];
173
+        $BorderR		= isset($Settings["BorderR"]) ? $Settings["BorderR"] : $this->Default["BorderR"];
174
+        $BorderG		= isset($Settings["BorderG"]) ? $Settings["BorderG"] : $this->Default["BorderG"];
175
+        $BorderB		= isset($Settings["BorderB"]) ? $Settings["BorderB"] : $this->Default["BorderB"];
176
+        $BorderAlpha	= isset($Settings["BorderAlpha"]) ? $Settings["BorderAlpha"] : $this->Default["BorderAlpha"];
177
+        $Surrounding	= isset($Settings["Surrounding"]) ? $Settings["Surrounding"] : $this->Default["Surrounding"];
178
+        $BackgroundR	= isset($Settings["BackgroundR"]) ? $Settings["BackgroundR"] : $this->Default["BackgroundR"];
179
+        $BackgroundG	= isset($Settings["BackgroundG"]) ? $Settings["BackgroundG"] : $this->Default["BackgroundG"];
180
+        $BackgroundB	= isset($Settings["BackgroundB"]) ? $Settings["BackgroundB"] : $this->Default["BackgroundB"];
181
+        $BackgroundAlpha	= isset($Settings["BackgroundAlpha"]) ? $Settings["BackgroundAlpha"] : $this->Default["BackgroundAlpha"];
182
+        $Force		= isset($Settings["Force"]) ? $Settings["Force"] :  $this->Default["Force"];
183
+        $NodeType		= isset($Settings["NodeType"]) ? $Settings["NodeType"] : $this->Default["NodeType"];
184
+        $Size		= isset($Settings["Size"]) ? $Settings["Size"] : $this->Default["Size"];
185
+        $Shape		= isset($Settings["Shape"]) ? $Settings["Shape"] : $this->Default["Shape"];
186
+        $FreeZone		= isset($Settings["FreeZone"]) ? $Settings["FreeZone"] : $this->Default["FreeZone"];
187
+
188
+        if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; }
189
+
190
+        $this->Data[$NodeID]["R"] = $R; $this->Data[$NodeID]["G"] = $G; $this->Data[$NodeID]["B"] = $B; $this->Data[$NodeID]["Alpha"] = $Alpha;
191
+        $this->Data[$NodeID]["BorderR"] = $BorderR; $this->Data[$NodeID]["BorderG"] = $BorderG; $this->Data[$NodeID]["BorderB"] = $BorderB; $this->Data[$NodeID]["BorderAlpha"] = $BorderAlpha;
192
+        $this->Data[$NodeID]["BackgroundR"]	= $BackgroundR; $this->Data[$NodeID]["BackgroundG"] = $BackgroundG; $this->Data[$NodeID]["BackgroundB"] = $BackgroundB; $this->Data[$NodeID]["BackgroundAlpha"] = $BackgroundAlpha;
193
+        $this->Data[$NodeID]["Name"]		= $Name;
194
+        $this->Data[$NodeID]["Force"]		= $Force;
195
+        $this->Data[$NodeID]["Type"]		= $NodeType;
196
+        $this->Data[$NodeID]["Size"]		= $Size;
197
+        $this->Data[$NodeID]["Shape"]		= $Shape;
198
+        $this->Data[$NodeID]["FreeZone"]		= $FreeZone;
199
+        if ( $Connections != NULL )
200
+        {
201
+        if ( is_array($Connections ) )
202
+        {
203
+            foreach($Connections as $Key => $Value)
204
+            $this->Data[$NodeID]["Connections"][] = $Value;
205
+        }
206
+        else
207 207
         $this->Data[$NodeID]["Connections"][] = $Connections;
208
-      }
208
+        }
209 209
     }
210 210
 
211
-   /* Set color attribute for a list of nodes */
212
-   function setNodesColor($Nodes,$Settings="")
211
+    /* Set color attribute for a list of nodes */
212
+    function setNodesColor($Nodes,$Settings="")
213 213
     {
214
-     if ( is_array($Nodes) )
215
-      {
216
-       foreach ($Nodes as $Key => $NodeID)
217
-        {
218
-         if (isset($this->Data[$NodeID]) )
219
-          {
220
-           if ( isset($Settings["R"]) ) { $this->Data[$NodeID]["R"] = $Settings["R"]; }
221
-           if ( isset($Settings["G"]) ) { $this->Data[$NodeID]["G"] = $Settings["G"]; }
222
-           if ( isset($Settings["B"]) ) { $this->Data[$NodeID]["B"] = $Settings["B"]; }
223
-           if ( isset($Settings["Alpha"]) ) { $this->Data[$NodeID]["Alpha"] = $Settings["Alpha"]; }
224
-           if ( isset($Settings["BorderR"]) ) { $this->Data[$NodeID]["BorderR"] = $Settings["BorderR"]; }
225
-           if ( isset($Settings["BorderG"]) ) { $this->Data[$NodeID]["BorderG"] = $Settings["BorderG"]; }
226
-           if ( isset($Settings["BorderB"]) ) { $this->Data[$NodeID]["BorderB"] = $Settings["BorderB"]; }
227
-           if ( isset($Settings["BorderAlpha"]) ) { $this->Data[$NodeID]["BorderAlpha"] = $Settings["BorderAlpha"]; }
228
-           if ( isset($Settings["Surrounding"]) ) { $this->Data[$NodeID]["BorderR"] = $this->Data[$NodeID]["R"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderG"] = $this->Data[$NodeID]["G"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderB"] = $this->Data[$NodeID]["B"] + $Settings["Surrounding"]; }
229
-          }
230
-        }
231
-      }
232
-     else
233
-      {
234
-       if ( isset($Settings["R"]) ) { $this->Data[$Nodes]["R"] = $Settings["R"]; }
235
-       if ( isset($Settings["G"]) ) { $this->Data[$Nodes]["G"] = $Settings["G"]; }
236
-       if ( isset($Settings["B"]) ) { $this->Data[$Nodes]["B"] = $Settings["B"]; }
237
-       if ( isset($Settings["Alpha"]) ) { $this->Data[$Nodes]["Alpha"] = $Settings["Alpha"]; }
238
-       if ( isset($Settings["BorderR"]) ) { $this->Data[$Nodes]["BorderR"] = $Settings["BorderR"]; }
239
-       if ( isset($Settings["BorderG"]) ) { $this->Data[$Nodes]["BorderG"] = $Settings["BorderG"]; }
240
-       if ( isset($Settings["BorderB"]) ) { $this->Data[$Nodes]["BorderB"] = $Settings["BorderB"]; }
241
-       if ( isset($Settings["BorderAlpha"]) ) { $this->Data[$Nodes]["BorderAlpha"] = $Settings["BorderAlpha"]; }
242
-       if ( isset($Settings["Surrounding"]) ) { $this->Data[$Nodes]["BorderR"] = $this->Data[$NodeID]["R"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderG"] = $this->Data[$NodeID]["G"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderB"] = $this->Data[$NodeID]["B"] + $Settings["Surrounding"]; }
243
-      }
214
+        if ( is_array($Nodes) )
215
+        {
216
+        foreach ($Nodes as $Key => $NodeID)
217
+        {
218
+            if (isset($this->Data[$NodeID]) )
219
+            {
220
+            if ( isset($Settings["R"]) ) { $this->Data[$NodeID]["R"] = $Settings["R"]; }
221
+            if ( isset($Settings["G"]) ) { $this->Data[$NodeID]["G"] = $Settings["G"]; }
222
+            if ( isset($Settings["B"]) ) { $this->Data[$NodeID]["B"] = $Settings["B"]; }
223
+            if ( isset($Settings["Alpha"]) ) { $this->Data[$NodeID]["Alpha"] = $Settings["Alpha"]; }
224
+            if ( isset($Settings["BorderR"]) ) { $this->Data[$NodeID]["BorderR"] = $Settings["BorderR"]; }
225
+            if ( isset($Settings["BorderG"]) ) { $this->Data[$NodeID]["BorderG"] = $Settings["BorderG"]; }
226
+            if ( isset($Settings["BorderB"]) ) { $this->Data[$NodeID]["BorderB"] = $Settings["BorderB"]; }
227
+            if ( isset($Settings["BorderAlpha"]) ) { $this->Data[$NodeID]["BorderAlpha"] = $Settings["BorderAlpha"]; }
228
+            if ( isset($Settings["Surrounding"]) ) { $this->Data[$NodeID]["BorderR"] = $this->Data[$NodeID]["R"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderG"] = $this->Data[$NodeID]["G"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderB"] = $this->Data[$NodeID]["B"] + $Settings["Surrounding"]; }
229
+            }
230
+        }
231
+        }
232
+        else
233
+        {
234
+        if ( isset($Settings["R"]) ) { $this->Data[$Nodes]["R"] = $Settings["R"]; }
235
+        if ( isset($Settings["G"]) ) { $this->Data[$Nodes]["G"] = $Settings["G"]; }
236
+        if ( isset($Settings["B"]) ) { $this->Data[$Nodes]["B"] = $Settings["B"]; }
237
+        if ( isset($Settings["Alpha"]) ) { $this->Data[$Nodes]["Alpha"] = $Settings["Alpha"]; }
238
+        if ( isset($Settings["BorderR"]) ) { $this->Data[$Nodes]["BorderR"] = $Settings["BorderR"]; }
239
+        if ( isset($Settings["BorderG"]) ) { $this->Data[$Nodes]["BorderG"] = $Settings["BorderG"]; }
240
+        if ( isset($Settings["BorderB"]) ) { $this->Data[$Nodes]["BorderB"] = $Settings["BorderB"]; }
241
+        if ( isset($Settings["BorderAlpha"]) ) { $this->Data[$Nodes]["BorderAlpha"] = $Settings["BorderAlpha"]; }
242
+        if ( isset($Settings["Surrounding"]) ) { $this->Data[$Nodes]["BorderR"] = $this->Data[$NodeID]["R"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderG"] = $this->Data[$NodeID]["G"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderB"] = $this->Data[$NodeID]["B"] + $Settings["Surrounding"]; }
243
+        }
244 244
     }
245 245
 
246
-   /* Returns all the nodes details */
247
-   function dumpNodes()
246
+    /* Returns all the nodes details */
247
+    function dumpNodes()
248 248
     { return($this->Data); }
249 249
 
250
-   /* Check if a connection exists and create it if required */
251
-   function checkConnection($SourceID, $TargetID)
250
+    /* Check if a connection exists and create it if required */
251
+    function checkConnection($SourceID, $TargetID)
252 252
     {
253
-     if ( isset($this->Data[$SourceID]["Connections"]) )
254
-      {
255
-       foreach ($this->Data[$SourceID]["Connections"] as $Key => $ConnectionID)
253
+        if ( isset($this->Data[$SourceID]["Connections"]) )
254
+        {
255
+        foreach ($this->Data[$SourceID]["Connections"] as $Key => $ConnectionID)
256 256
         { if ( $TargetID == $ConnectionID ) { return(TRUE); } }
257
-      }
258
-     $this->Data[$SourceID]["Connections"][] = $TargetID;
257
+        }
258
+        $this->Data[$SourceID]["Connections"][] = $TargetID;
259 259
     }
260
-   /* Get the median linked nodes position */
261
-   function getMedianOffset($Key,$X,$Y)
260
+    /* Get the median linked nodes position */
261
+    function getMedianOffset($Key,$X,$Y)
262 262
     {
263
-     $Cpt = 1;
264
-     if ( isset($this->Data[$Key]["Connections"]) )
265
-      {
266
-       foreach($this->Data[$Key]["Connections"] as $ID => $NodeID)
267
-        {
268
-         if ( isset($this->Data[$NodeID]["X"]) && isset($this->Data[$NodeID]["Y"]) )
269
-          {
270
-           $X = $X + $this->Data[$NodeID]["X"];
271
-           $Y = $Y + $this->Data[$NodeID]["Y"];
272
-           $Cpt++;
273
-          }
274
-        }
275
-      }
276
-     return(array("X"=>$X/$Cpt,"Y"=>$Y/$Cpt));
263
+        $Cpt = 1;
264
+        if ( isset($this->Data[$Key]["Connections"]) )
265
+        {
266
+        foreach($this->Data[$Key]["Connections"] as $ID => $NodeID)
267
+        {
268
+            if ( isset($this->Data[$NodeID]["X"]) && isset($this->Data[$NodeID]["Y"]) )
269
+            {
270
+            $X = $X + $this->Data[$NodeID]["X"];
271
+            $Y = $Y + $this->Data[$NodeID]["Y"];
272
+            $Cpt++;
273
+            }
274
+        }
275
+        }
276
+        return(array("X"=>$X/$Cpt,"Y"=>$Y/$Cpt));
277 277
     }
278 278
 
279
-   /* Return the ID of the attached partner with the biggest weight */
280
-   function getBiggestPartner($Key)
279
+    /* Return the ID of the attached partner with the biggest weight */
280
+    function getBiggestPartner($Key)
281 281
     {
282
-     if ( !isset($this->Data[$Key]["Connections"]) ) { return(""); }
282
+        if ( !isset($this->Data[$Key]["Connections"]) ) { return(""); }
283 283
 
284
-     $MaxWeight = 0; $Result = "";
285
-     foreach($this->Data[$Key]["Connections"] as $Key => $PeerID)
286
-      {
287
-       if ( $this->Data[$PeerID]["Weight"] > $MaxWeight )
284
+        $MaxWeight = 0; $Result = "";
285
+        foreach($this->Data[$Key]["Connections"] as $Key => $PeerID)
286
+        {
287
+        if ( $this->Data[$PeerID]["Weight"] > $MaxWeight )
288 288
         { $MaxWeight = $this->Data[$PeerID]["Weight"]; $Result = $PeerID; }
289
-      }
290
-     return($Result);
289
+        }
290
+        return($Result);
291 291
     }
292 292
 
293
-   /* Do the initial node positions computing pass */
294
-   function firstPass($Algorithm)
293
+    /* Do the initial node positions computing pass */
294
+    function firstPass($Algorithm)
295 295
     {
296
-     $CenterX = ($this->X2 - $this->X1) / 2 + $this->X1;
297
-     $CenterY = ($this->Y2 - $this->Y1) / 2 + $this->Y1;
296
+        $CenterX = ($this->X2 - $this->X1) / 2 + $this->X1;
297
+        $CenterY = ($this->Y2 - $this->Y1) / 2 + $this->Y1;
298 298
 
299
-     /* Check connections reciprocity */
300
-     foreach($this->Data as $Key => $Settings)
301
-      {
302
-       if ( isset($Settings["Connections"]) )
299
+        /* Check connections reciprocity */
300
+        foreach($this->Data as $Key => $Settings)
301
+        {
302
+        if ( isset($Settings["Connections"]) )
303 303
         {
304
-         foreach($Settings["Connections"] as $ID => $ConnectionID)
305
-          $this->checkConnection($ConnectionID,$Key);
304
+            foreach($Settings["Connections"] as $ID => $ConnectionID)
305
+            $this->checkConnection($ConnectionID,$Key);
306
+        }
306 307
         }
307
-      }
308 308
 
309
-     if ( $this->AutoComputeFreeZone ) { $this->autoFreeZone(); }
309
+        if ( $this->AutoComputeFreeZone ) { $this->autoFreeZone(); }
310 310
 
311
-     /* Get the max number of connections */
312
-     $MaxConnections = 0;
313
-     foreach($this->Data as $Key => $Settings)
314
-      { if ( isset($Settings["Connections"]) ) { if ( $MaxConnections < count($Settings["Connections"] ) ) { $MaxConnections = count($Settings["Connections"]); } } }
311
+        /* Get the max number of connections */
312
+        $MaxConnections = 0;
313
+        foreach($this->Data as $Key => $Settings)
314
+        { if ( isset($Settings["Connections"]) ) { if ( $MaxConnections < count($Settings["Connections"] ) ) { $MaxConnections = count($Settings["Connections"]); } } }
315 315
 
316
-     if ( $Algorithm == ALGORITHM_WEIGHTED )
317
-      {
318
-       foreach($this->Data as $Key => $Settings)
316
+        if ( $Algorithm == ALGORITHM_WEIGHTED )
317
+        {
318
+        foreach($this->Data as $Key => $Settings)
319 319
         {
320
-         if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; }
321
-         if ( $Settings["Type"] == NODE_TYPE_FREE )
322
-          {
323
-           if ( isset($Settings["Connections"]) )
320
+            if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; }
321
+            if ( $Settings["Type"] == NODE_TYPE_FREE )
322
+            {
323
+            if ( isset($Settings["Connections"]) )
324 324
             { $Connections = count($Settings["Connections"]); }
325
-           else
325
+            else
326 326
             { $Connections = 0; }
327 327
 
328
-           $Ring  = $MaxConnections - $Connections;
329
-           $Angle = rand(0,360);
328
+            $Ring  = $MaxConnections - $Connections;
329
+            $Angle = rand(0,360);
330 330
            
331
-           $this->Data[$Key]["X"] = cos(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterX;
332
-           $this->Data[$Key]["Y"] = sin(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterY;
333
-          }
331
+            $this->Data[$Key]["X"] = cos(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterX;
332
+            $this->Data[$Key]["Y"] = sin(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterY;
333
+            }
334 334
         }
335
-      }
336
-     elseif ( $Algorithm == ALGORITHM_CENTRAL )
337
-      {
338
-       /* Put a weight on each nodes */
339
-       foreach($this->Data as $Key => $Settings)
335
+        }
336
+        elseif ( $Algorithm == ALGORITHM_CENTRAL )
337
+        {
338
+        /* Put a weight on each nodes */
339
+        foreach($this->Data as $Key => $Settings)
340 340
         {
341
-         if ( isset($Settings["Connections"]) )
342
-          $this->Data[$Key]["Weight"] = count($Settings["Connections"]);
343
-         else
344
-          $this->Data[$Key]["Weight"] = 0;
341
+            if ( isset($Settings["Connections"]) )
342
+            $this->Data[$Key]["Weight"] = count($Settings["Connections"]);
343
+            else
344
+            $this->Data[$Key]["Weight"] = 0;
345 345
         }
346 346
 
347
-       $MaxConnections = $MaxConnections + 1;
348
-       for($i=$MaxConnections;$i>=0;$i--)
347
+        $MaxConnections = $MaxConnections + 1;
348
+        for($i=$MaxConnections;$i>=0;$i--)
349 349
         {
350
-         foreach($this->Data as $Key => $Settings)
351
-          {
352
-           if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; }
353
-           if ( $Settings["Type"] == NODE_TYPE_FREE )
350
+            foreach($this->Data as $Key => $Settings)
354 351
             {
355
-             if ( isset($Settings["Connections"]) )
356
-              { $Connections = count($Settings["Connections"]); }
357
-             else
358
-              { $Connections = 0; }
359
-
360
-             if ( $Connections == $i )
361
-              {
362
-               $BiggestPartner = $this->getBiggestPartner($Key);
363
-               if ( $BiggestPartner != "" )
352
+            if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; }
353
+            if ( $Settings["Type"] == NODE_TYPE_FREE )
354
+            {
355
+                if ( isset($Settings["Connections"]) )
356
+                { $Connections = count($Settings["Connections"]); }
357
+                else
358
+                { $Connections = 0; }
359
+
360
+                if ( $Connections == $i )
364 361
                 {
365
-                 $Ring          = $this->Data[$BiggestPartner]["FreeZone"];
366
-                 $Weight        = $this->Data[$BiggestPartner]["Weight"];
367
-                 $AngleDivision = 360 / $this->Data[$BiggestPartner]["Weight"];
368
-                 $Done          = FALSE; $Tries = 0;
369
-                 while (!$Done && $Tries <= $Weight*2)
370
-                  {
371
-                   $Tries++;
372
-                   $Angle = floor(rand(0,$Weight)*$AngleDivision);
373
-                   if ( !isset($this->Data[$BiggestPartner]["Angular"][$Angle]) || !isset($this->Data[$BiggestPartner]["Angular"]) )
362
+                $BiggestPartner = $this->getBiggestPartner($Key);
363
+                if ( $BiggestPartner != "" )
364
+                {
365
+                    $Ring          = $this->Data[$BiggestPartner]["FreeZone"];
366
+                    $Weight        = $this->Data[$BiggestPartner]["Weight"];
367
+                    $AngleDivision = 360 / $this->Data[$BiggestPartner]["Weight"];
368
+                    $Done          = FALSE; $Tries = 0;
369
+                    while (!$Done && $Tries <= $Weight*2)
370
+                    {
371
+                    $Tries++;
372
+                    $Angle = floor(rand(0,$Weight)*$AngleDivision);
373
+                    if ( !isset($this->Data[$BiggestPartner]["Angular"][$Angle]) || !isset($this->Data[$BiggestPartner]["Angular"]) )
374 374
                     {
375
-                     $this->Data[$BiggestPartner]["Angular"][$Angle] = $Angle;
376
-                     $Done = TRUE; 
375
+                        $this->Data[$BiggestPartner]["Angular"][$Angle] = $Angle;
376
+                        $Done = TRUE; 
377 377
                     }
378
-                  }
379
-                 if ( !$Done )
380
-                  { $Angle = rand(0,360); $this->Data[$BiggestPartner]["Angular"][$Angle] = $Angle; }
378
+                    }
379
+                    if ( !$Done )
380
+                    { $Angle = rand(0,360); $this->Data[$BiggestPartner]["Angular"][$Angle] = $Angle; }
381 381
 
382
-                 $X = cos(deg2rad($Angle)) * ($Ring) + $this->Data[$BiggestPartner]["X"];
383
-                 $Y = sin(deg2rad($Angle)) * ($Ring) + $this->Data[$BiggestPartner]["Y"];
382
+                    $X = cos(deg2rad($Angle)) * ($Ring) + $this->Data[$BiggestPartner]["X"];
383
+                    $Y = sin(deg2rad($Angle)) * ($Ring) + $this->Data[$BiggestPartner]["Y"];
384 384
 
385
-                 $this->Data[$Key]["X"] = $X;
386
-                 $this->Data[$Key]["Y"] = $Y;
385
+                    $this->Data[$Key]["X"] = $X;
386
+                    $this->Data[$Key]["Y"] = $Y;
387
+                }
387 388
                 }
388
-              }
389 389
             }
390
-          }
391
-        }
392
-      }
393
-     elseif ( $Algorithm == ALGORITHM_CIRCULAR )
394
-      {
395
-       $MaxConnections = $MaxConnections + 1;
396
-       for($i=$MaxConnections;$i>=0;$i--)
397
-        {
398
-         foreach($this->Data as $Key => $Settings)
399
-          {
400
-           if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; }
401
-           if ( $Settings["Type"] == NODE_TYPE_FREE )
390
+            }
391
+        }
392
+        }
393
+        elseif ( $Algorithm == ALGORITHM_CIRCULAR )
394
+        {
395
+        $MaxConnections = $MaxConnections + 1;
396
+        for($i=$MaxConnections;$i>=0;$i--)
397
+        {
398
+            foreach($this->Data as $Key => $Settings)
399
+            {
400
+            if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; }
401
+            if ( $Settings["Type"] == NODE_TYPE_FREE )
402 402
             {
403
-             if ( isset($Settings["Connections"]) )
404
-              { $Connections = count($Settings["Connections"]); }
405
-             else
406
-              { $Connections = 0; }
403
+                if ( isset($Settings["Connections"]) )
404
+                { $Connections = count($Settings["Connections"]); }
405
+                else
406
+                { $Connections = 0; }
407 407
 
408
-             if ( $Connections == $i )
409
-              {
410
-               $Ring  = $MaxConnections - $Connections;
411
-               $Angle = rand(0,360);
408
+                if ( $Connections == $i )
409
+                {
410
+                $Ring  = $MaxConnections - $Connections;
411
+                $Angle = rand(0,360);
412 412
 
413
-               $X = cos(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterX;
414
-               $Y = sin(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterY;
413
+                $X = cos(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterX;
414
+                $Y = sin(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterY;
415 415
 
416
-               $MedianOffset = $this->getMedianOffset($Key,$X,$Y);
416
+                $MedianOffset = $this->getMedianOffset($Key,$X,$Y);
417 417
 
418
-               $this->Data[$Key]["X"] = $MedianOffset["X"];
419
-               $this->Data[$Key]["Y"] = $MedianOffset["Y"];
420
-              }
418
+                $this->Data[$Key]["X"] = $MedianOffset["X"];
419
+                $this->Data[$Key]["Y"] = $MedianOffset["Y"];
420
+                }
421 421
             }
422
-          }
422
+            }
423
+        }
423 424
         }
424
-      }
425
-     elseif ( $Algorithm == ALGORITHM_RANDOM )
426
-      {
427
-       foreach($this->Data as $Key => $Settings)
425
+        elseif ( $Algorithm == ALGORITHM_RANDOM )
428 426
         {
429
-         if ( $Settings["Type"] == NODE_TYPE_FREE )
430
-          {
431
-           $this->Data[$Key]["X"] = $CenterX + rand(-20,20);
432
-           $this->Data[$Key]["Y"] = $CenterY + rand(-20,20);
433
-          }
434
-         if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; }
427
+        foreach($this->Data as $Key => $Settings)
428
+        {
429
+            if ( $Settings["Type"] == NODE_TYPE_FREE )
430
+            {
431
+            $this->Data[$Key]["X"] = $CenterX + rand(-20,20);
432
+            $this->Data[$Key]["Y"] = $CenterY + rand(-20,20);
433
+            }
434
+            if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; }
435
+        }
435 436
         }
436
-      }
437 437
     }
438 438
 
439
-   /* Compute one pass */
440
-   function doPass()
439
+    /* Compute one pass */
440
+    function doPass()
441 441
     {
442
-     /* Compute vectors */
443
-     foreach($this->Data as $Key => $Settings)
444
-      {
445
-       if ( $Settings["Type"] != NODE_TYPE_CENTRAL )
442
+        /* Compute vectors */
443
+        foreach($this->Data as $Key => $Settings)
446 444
         {
447
-         unset($this->Data[$Key]["Vectors"]);
445
+        if ( $Settings["Type"] != NODE_TYPE_CENTRAL )
446
+        {
447
+            unset($this->Data[$Key]["Vectors"]);
448 448
 
449
-         $X1 = $Settings["X"];
450
-         $Y1 = $Settings["Y"];
449
+            $X1 = $Settings["X"];
450
+            $Y1 = $Settings["Y"];
451 451
 
452
-         /* Repulsion vectors */
453
-         foreach($this->Data as $Key2 => $Settings2)
454
-          {
455
-           if ( $Key != $Key2 )
452
+            /* Repulsion vectors */
453
+            foreach($this->Data as $Key2 => $Settings2)
454
+            {
455
+            if ( $Key != $Key2 )
456 456
             {
457
-             $X2 = $this->Data[$Key2]["X"];
458
-             $Y2 = $this->Data[$Key2]["Y"];
459
-             $FreeZone = $this->Data[$Key2]["FreeZone"];
460
-
461
-             $Distance = $this->getDistance($X1,$Y1,$X2,$Y2);
462
-             $Angle    = $this->getAngle($X1,$Y1,$X2,$Y2) + 180;
463
-
464
-             /* Nodes too close, repulsion occurs */
465
-             if ( $Distance < $FreeZone )
466
-              {
467
-               $Force = log(pow(2,$FreeZone-$Distance));
468
-               if ( $Force > 1 )
457
+                $X2 = $this->Data[$Key2]["X"];
458
+                $Y2 = $this->Data[$Key2]["Y"];
459
+                $FreeZone = $this->Data[$Key2]["FreeZone"];
460
+
461
+                $Distance = $this->getDistance($X1,$Y1,$X2,$Y2);
462
+                $Angle    = $this->getAngle($X1,$Y1,$X2,$Y2) + 180;
463
+
464
+                /* Nodes too close, repulsion occurs */
465
+                if ( $Distance < $FreeZone )
466
+                {
467
+                $Force = log(pow(2,$FreeZone-$Distance));
468
+                if ( $Force > 1 )
469 469
                 { $this->Data[$Key]["Vectors"][] = array("Type"=>"R","Angle"=>$Angle % 360,"Force"=>$Force); }
470
-              }
470
+                }
471
+            }
471 472
             }
472
-          }
473 473
 
474
-         /* Attraction vectors */
475
-         if ( isset($Settings["Connections"]) )
476
-          {
477
-           foreach($Settings["Connections"] as $ID => $NodeID)
474
+            /* Attraction vectors */
475
+            if ( isset($Settings["Connections"]) )
478 476
             {
479
-             if ( isset($this->Data[$NodeID]) )
480
-              {
481
-               $X2 = $this->Data[$NodeID]["X"];
482
-               $Y2 = $this->Data[$NodeID]["Y"];
483
-               $FreeZone = $this->Data[$Key2]["FreeZone"];
477
+            foreach($Settings["Connections"] as $ID => $NodeID)
478
+            {
479
+                if ( isset($this->Data[$NodeID]) )
480
+                {
481
+                $X2 = $this->Data[$NodeID]["X"];
482
+                $Y2 = $this->Data[$NodeID]["Y"];
483
+                $FreeZone = $this->Data[$Key2]["FreeZone"];
484 484
 
485
-               $Distance = $this->getDistance($X1,$Y1,$X2,$Y2);
486
-               $Angle    = $this->getAngle($X1,$Y1,$X2,$Y2);
485
+                $Distance = $this->getDistance($X1,$Y1,$X2,$Y2);
486
+                $Angle    = $this->getAngle($X1,$Y1,$X2,$Y2);
487 487
 
488
-               if ( $Distance > $FreeZone )
488
+                if ( $Distance > $FreeZone )
489 489
                 $Force = log(($Distance-$FreeZone)+1);
490
-               else
490
+                else
491 491
                 { $Force = log(($FreeZone-$Distance)+1); ($Angle = $Angle + 180); }
492 492
 
493
-               if ( $Force > 1 )
493
+                if ( $Force > 1 )
494 494
                 $this->Data[$Key]["Vectors"][] = array("Type"=>"A","Angle"=>$Angle % 360,"Force"=>$Force);
495
-              }
495
+                }
496
+            }
496 497
             }
497
-          }
498 498
         }
499
-      }
499
+        }
500 500
 
501
-     /* Move the nodes accoding to the vectors */
502
-     foreach($this->Data as $Key => $Settings)
503
-      {
504
-       $X = $Settings["X"];
505
-       $Y = $Settings["Y"];
501
+        /* Move the nodes accoding to the vectors */
502
+        foreach($this->Data as $Key => $Settings)
503
+        {
504
+        $X = $Settings["X"];
505
+        $Y = $Settings["Y"];
506 506
 
507
-       if ( isset($Settings["Vectors"]) && $Settings["Type"] != NODE_TYPE_CENTRAL )
507
+        if ( isset($Settings["Vectors"]) && $Settings["Type"] != NODE_TYPE_CENTRAL )
508 508
         {
509
-         foreach($Settings["Vectors"] as $ID => $Vector)
510
-          {
511
-           $Type  = $Vector["Type"];
512
-           $Force = $Vector["Force"];
513
-           $Angle = $Vector["Angle"];
514
-           $Factor = $Type == "A" ? $this->MagneticForceA : $this->MagneticForceR;
509
+            foreach($Settings["Vectors"] as $ID => $Vector)
510
+            {
511
+            $Type  = $Vector["Type"];
512
+            $Force = $Vector["Force"];
513
+            $Angle = $Vector["Angle"];
514
+            $Factor = $Type == "A" ? $this->MagneticForceA : $this->MagneticForceR;
515 515
 
516
-           $X = cos(deg2rad($Angle)) * $Force * $Factor + $X;
517
-           $Y = sin(deg2rad($Angle)) * $Force * $Factor + $Y;
518
-          }
516
+            $X = cos(deg2rad($Angle)) * $Force * $Factor + $X;
517
+            $Y = sin(deg2rad($Angle)) * $Force * $Factor + $Y;
518
+            }
519 519
         }
520 520
 
521
-       $this->Data[$Key]["X"] = $X;
522
-       $this->Data[$Key]["Y"] = $Y;
523
-      }
521
+        $this->Data[$Key]["X"] = $X;
522
+        $this->Data[$Key]["Y"] = $Y;
523
+        }
524 524
     }
525 525
 
526
-   function lastPass()
526
+    function lastPass()
527 527
     {
528
-     /* Put everything inside the graph area */
529
-     foreach($this->Data as $Key => $Settings)
530
-      {
531
-       $X = $Settings["X"];
532
-       $Y = $Settings["Y"];
533
-
534
-       if ( $X < $this->X1 ) { $X = $this->X1; }
535
-       if ( $X > $this->X2 ) { $X = $this->X2; }
536
-       if ( $Y < $this->Y1 ) { $Y = $this->Y1; }
537
-       if ( $Y > $this->Y2 ) { $Y = $this->Y2; }
538
-
539
-       $this->Data[$Key]["X"] = $X;
540
-       $this->Data[$Key]["Y"] = $Y;
541
-      }
542
-
543
-     /* Dump all links */
544
-     $Links = "";
545
-     foreach($this->Data as $Key => $Settings)
546
-      {
547
-       $X1 = $Settings["X"];
548
-       $Y1 = $Settings["Y"];
549
-
550
-       if ( isset($Settings["Connections"]) )
551
-        {
552
-         foreach ($Settings["Connections"] as $ID => $NodeID)
553
-          {
554
-           if ( isset($this->Data[$NodeID]) )
528
+        /* Put everything inside the graph area */
529
+        foreach($this->Data as $Key => $Settings)
530
+        {
531
+        $X = $Settings["X"];
532
+        $Y = $Settings["Y"];
533
+
534
+        if ( $X < $this->X1 ) { $X = $this->X1; }
535
+        if ( $X > $this->X2 ) { $X = $this->X2; }
536
+        if ( $Y < $this->Y1 ) { $Y = $this->Y1; }
537
+        if ( $Y > $this->Y2 ) { $Y = $this->Y2; }
538
+
539
+        $this->Data[$Key]["X"] = $X;
540
+        $this->Data[$Key]["Y"] = $Y;
541
+        }
542
+
543
+        /* Dump all links */
544
+        $Links = "";
545
+        foreach($this->Data as $Key => $Settings)
546
+        {
547
+        $X1 = $Settings["X"];
548
+        $Y1 = $Settings["Y"];
549
+
550
+        if ( isset($Settings["Connections"]) )
551
+        {
552
+            foreach ($Settings["Connections"] as $ID => $NodeID)
553
+            {
554
+            if ( isset($this->Data[$NodeID]) )
555 555
             {
556
-             $X2 = $this->Data[$NodeID]["X"];
557
-             $Y2 = $this->Data[$NodeID]["Y"];
556
+                $X2 = $this->Data[$NodeID]["X"];
557
+                $Y2 = $this->Data[$NodeID]["Y"];
558 558
 
559
-             $Links[] = array("X1"=>$X1,"Y1"=>$Y1,"X2"=>$X2,"Y2"=>$Y2,"Source"=>$Settings["Name"],"Destination"=>$this->Data[$NodeID]["Name"]);
559
+                $Links[] = array("X1"=>$X1,"Y1"=>$Y1,"X2"=>$X2,"Y2"=>$Y2,"Source"=>$Settings["Name"],"Destination"=>$this->Data[$NodeID]["Name"]);
560 560
             }
561
-          }
561
+            }
562
+        }
562 563
         }
563
-      }
564 564
 
565
-     /* Check collisions */
566
-     $Conflicts = 0;
567
-     foreach($this->Data as $Key => $Settings)
568
-      {
569
-       $X1 = $Settings["X"];
570
-       $Y1 = $Settings["Y"];
565
+        /* Check collisions */
566
+        $Conflicts = 0;
567
+        foreach($this->Data as $Key => $Settings)
568
+        {
569
+        $X1 = $Settings["X"];
570
+        $Y1 = $Settings["Y"];
571 571
 
572
-       if ( isset($Settings["Connections"]) )
572
+        if ( isset($Settings["Connections"]) )
573 573
         {
574
-         foreach ($Settings["Connections"] as $ID => $NodeID)
575
-          {
576
-           if ( isset($this->Data[$NodeID]) )
574
+            foreach ($Settings["Connections"] as $ID => $NodeID)
575
+            {
576
+            if ( isset($this->Data[$NodeID]) )
577 577
             {
578
-             $X2 = $this->Data[$NodeID]["X"];
579
-             $Y2 = $this->Data[$NodeID]["Y"];
578
+                $X2 = $this->Data[$NodeID]["X"];
579
+                $Y2 = $this->Data[$NodeID]["Y"];
580 580
 
581
-             foreach($Links as $IDLinks => $Link)
582
-              {
583
-               $X3 = $Link["X1"]; $Y3 = $Link["Y1"]; $X4 = $Link["X2"]; $Y4 = $Link["Y2"];
581
+                foreach($Links as $IDLinks => $Link)
582
+                {
583
+                $X3 = $Link["X1"]; $Y3 = $Link["Y1"]; $X4 = $Link["X2"]; $Y4 = $Link["Y2"];
584 584
 
585
-               if ( !($X1 == $X3 && $X2 == $X4 && $Y1 == $Y3 && $Y2 == $Y4 ) )
585
+                if ( !($X1 == $X3 && $X2 == $X4 && $Y1 == $Y3 && $Y2 == $Y4 ) )
586 586
                 {
587
-                 if ( $this->intersect($X1,$Y1,$X2,$Y2,$X3,$Y3,$X4,$Y4) )
588
-                  {
589
-                   if ( $Link["Source"] != $Settings["Name"] && $Link["Source"] != $this->Data[$NodeID]["Name"] && $Link["Destination"] != $Settings["Name"] && $Link["Destination"] != $this->Data[$NodeID]["Name"] )
587
+                    if ( $this->intersect($X1,$Y1,$X2,$Y2,$X3,$Y3,$X4,$Y4) )
588
+                    {
589
+                    if ( $Link["Source"] != $Settings["Name"] && $Link["Source"] != $this->Data[$NodeID]["Name"] && $Link["Destination"] != $Settings["Name"] && $Link["Destination"] != $this->Data[$NodeID]["Name"] )
590 590
                     { $Conflicts++; }
591
-                  }
591
+                    }
592
+                }
592 593
                 }
593
-              }
594 594
             }
595
-          }
595
+            }
596
+        }
596 597
         }
597
-      }
598
-     return($Conflicts/2);
598
+        return($Conflicts/2);
599 599
     }
600 600
 
601
-   /* Center the graph */
602
-   function center()
601
+    /* Center the graph */
602
+    function center()
603 603
     {
604
-     /* Determine the real center */
605
-     $TargetCenterX = ($this->X2 - $this->X1) / 2 + $this->X1;
606
-     $TargetCenterY = ($this->Y2 - $this->Y1) / 2 + $this->Y1;
607
-
608
-     /* Get current boundaries */
609
-     $XMin = $this->X2; $XMax = $this->X1;
610
-     $YMin = $this->Y2; $YMax = $this->Y1;
611
-     foreach($this->Data as $Key => $Settings)
612
-      {
613
-       $X = $Settings["X"];
614
-       $Y = $Settings["Y"];
615
-
616
-       if ( $X < $XMin) { $XMin = $X; }
617
-       if ( $X > $XMax) { $XMax = $X; }
618
-       if ( $Y < $YMin) { $YMin = $Y; }
619
-       if ( $Y > $YMax) { $YMax = $Y; }
620
-      }
621
-     $CurrentCenterX = ($XMax - $XMin) / 2 + $XMin;
622
-     $CurrentCenterY = ($YMax - $YMin) / 2 + $YMin;
623
-
624
-     /* Compute the offset to apply */
625
-     $XOffset = $TargetCenterX - $CurrentCenterX;
626
-     $YOffset = $TargetCenterY - $CurrentCenterY;
627
-
628
-     /* Correct the points position */
629
-     foreach($this->Data as $Key => $Settings)
630
-      {
631
-       $this->Data[$Key]["X"] = $Settings["X"] + $XOffset;
632
-       $this->Data[$Key]["Y"] = $Settings["Y"] + $YOffset;
633
-      }
634
-    }
604
+        /* Determine the real center */
605
+        $TargetCenterX = ($this->X2 - $this->X1) / 2 + $this->X1;
606
+        $TargetCenterY = ($this->Y2 - $this->Y1) / 2 + $this->Y1;
607
+
608
+        /* Get current boundaries */
609
+        $XMin = $this->X2; $XMax = $this->X1;
610
+        $YMin = $this->Y2; $YMax = $this->Y1;
611
+        foreach($this->Data as $Key => $Settings)
612
+        {
613
+        $X = $Settings["X"];
614
+        $Y = $Settings["Y"];
635 615
 
636
-   /* Create the encoded string */
637
-   function drawSpring($Object,$Settings="")
638
-    {
639
-     $this->pChartObject = $Object;
616
+        if ( $X < $XMin) { $XMin = $X; }
617
+        if ( $X > $XMax) { $XMax = $X; }
618
+        if ( $Y < $YMin) { $YMin = $Y; }
619
+        if ( $Y > $YMax) { $YMax = $Y; }
620
+        }
621
+        $CurrentCenterX = ($XMax - $XMin) / 2 + $XMin;
622
+        $CurrentCenterY = ($YMax - $YMin) / 2 + $YMin;
640 623
 
641
-     $Pass			= isset($Settings["Pass"]) ? $Settings["Pass"] : 50;
642
-     $Retries			= isset($Settings["Retry"]) ? $Settings["Retry"] : 10;
643
-     $this->MagneticForceA	= isset($Settings["MagneticForceA"]) ? $Settings["MagneticForceA"] : 1.5;
644
-     $this->MagneticForceR	= isset($Settings["MagneticForceR"]) ? $Settings["MagneticForceR"] : 2;
645
-     $this->RingSize		= isset($Settings["RingSize"]) ? $Settings["RingSize"] : 40;
646
-     $DrawVectors		= isset($Settings["DrawVectors"]) ? $Settings["DrawVectors"] : FALSE;
647
-     $DrawQuietZone		= isset($Settings["DrawQuietZone"]) ? $Settings["DrawQuietZone"] : FALSE;
648
-     $CenterGraph		= isset($Settings["CenterGraph"]) ? $Settings["CenterGraph"] : TRUE;
649
-     $TextPadding		= isset($Settings["TextPadding"]) ? $Settings["TextPadding"] : 4;
650
-     $Algorithm			= isset($Settings["Algorithm"]) ? $Settings["Algorithm"] : ALGORITHM_WEIGHTED;
624
+        /* Compute the offset to apply */
625
+        $XOffset = $TargetCenterX - $CurrentCenterX;
626
+        $YOffset = $TargetCenterY - $CurrentCenterY;
651 627
 
652
-     $FontSize		= $Object->FontSize;
653
-     $this->X1		= $Object->GraphAreaX1;
654
-     $this->Y1		= $Object->GraphAreaY1;
655
-     $this->X2		= $Object->GraphAreaX2;
656
-     $this->Y2		= $Object->GraphAreaY2;
628
+        /* Correct the points position */
629
+        foreach($this->Data as $Key => $Settings)
630
+        {
631
+        $this->Data[$Key]["X"] = $Settings["X"] + $XOffset;
632
+        $this->Data[$Key]["Y"] = $Settings["Y"] + $YOffset;
633
+        }
634
+    }
657 635
 
658
-     $Conflicts = 1; $Jobs = 0; $this->History["MinimumConflicts"] = -1;
659
-     while ($Conflicts != 0 && $Jobs < $Retries )
660
-      {
661
-       $Jobs++;
636
+    /* Create the encoded string */
637
+    function drawSpring($Object,$Settings="")
638
+    {
639
+        $this->pChartObject = $Object;
640
+
641
+        $Pass			= isset($Settings["Pass"]) ? $Settings["Pass"] : 50;
642
+        $Retries			= isset($Settings["Retry"]) ? $Settings["Retry"] : 10;
643
+        $this->MagneticForceA	= isset($Settings["MagneticForceA"]) ? $Settings["MagneticForceA"] : 1.5;
644
+        $this->MagneticForceR	= isset($Settings["MagneticForceR"]) ? $Settings["MagneticForceR"] : 2;
645
+        $this->RingSize		= isset($Settings["RingSize"]) ? $Settings["RingSize"] : 40;
646
+        $DrawVectors		= isset($Settings["DrawVectors"]) ? $Settings["DrawVectors"] : FALSE;
647
+        $DrawQuietZone		= isset($Settings["DrawQuietZone"]) ? $Settings["DrawQuietZone"] : FALSE;
648
+        $CenterGraph		= isset($Settings["CenterGraph"]) ? $Settings["CenterGraph"] : TRUE;
649
+        $TextPadding		= isset($Settings["TextPadding"]) ? $Settings["TextPadding"] : 4;
650
+        $Algorithm			= isset($Settings["Algorithm"]) ? $Settings["Algorithm"] : ALGORITHM_WEIGHTED;
651
+
652
+        $FontSize		= $Object->FontSize;
653
+        $this->X1		= $Object->GraphAreaX1;
654
+        $this->Y1		= $Object->GraphAreaY1;
655
+        $this->X2		= $Object->GraphAreaX2;
656
+        $this->Y2		= $Object->GraphAreaY2;
657
+
658
+        $Conflicts = 1; $Jobs = 0; $this->History["MinimumConflicts"] = -1;
659
+        while ($Conflicts != 0 && $Jobs < $Retries )
660
+        {
661
+        $Jobs++;
662 662
 
663
-       /* Compute the initial settings */
664
-       $this->firstPass($Algorithm);
663
+        /* Compute the initial settings */
664
+        $this->firstPass($Algorithm);
665 665
 
666
-       /* Apply the vectors */
667
-       if ( $Pass > 0 ) 
666
+        /* Apply the vectors */
667
+        if ( $Pass > 0 ) 
668 668
         {
669
-         for ($i=0; $i<=$Pass; $i++) { $this->doPass(); }
669
+            for ($i=0; $i<=$Pass; $i++) { $this->doPass(); }
670 670
         }
671 671
 
672
-       $Conflicts = $this->lastPass();
673
-       if ( $this->History["MinimumConflicts"] == -1 || $Conflicts < $this->History["MinimumConflicts"] )
672
+        $Conflicts = $this->lastPass();
673
+        if ( $this->History["MinimumConflicts"] == -1 || $Conflicts < $this->History["MinimumConflicts"] )
674 674
         { $this->History["MinimumConflicts"] = $Conflicts; $this->History["Result"] = $this->Data; }
675
-      }
675
+        }
676 676
 
677
-     $Conflicts  = $this->History["MinimumConflicts"];
678
-     $this->Data = $this->History["Result"];
677
+        $Conflicts  = $this->History["MinimumConflicts"];
678
+        $this->Data = $this->History["Result"];
679 679
 
680
-     if ( $CenterGraph ) { $this->center(); }
680
+        if ( $CenterGraph ) { $this->center(); }
681 681
 
682
-     /* Draw the connections */
683
-     $Drawn = "";
684
-     foreach($this->Data as $Key => $Settings)
685
-      {
686
-       $X	= $Settings["X"];
687
-       $Y	= $Settings["Y"];
682
+        /* Draw the connections */
683
+        $Drawn = "";
684
+        foreach($this->Data as $Key => $Settings)
685
+        {
686
+        $X	= $Settings["X"];
687
+        $Y	= $Settings["Y"];
688 688
 
689
-       if ( isset($Settings["Connections"]) )
689
+        if ( isset($Settings["Connections"]) )
690 690
         {
691
-         foreach ($Settings["Connections"] as $ID => $NodeID)
692
-          {
693
-           if ( !isset($Drawn[$Key]) )    { $Drawn[$Key] = ""; }
694
-           if ( !isset($Drawn[$NodeID]) ) { $Drawn[$NodeID] = ""; }
691
+            foreach ($Settings["Connections"] as $ID => $NodeID)
692
+            {
693
+            if ( !isset($Drawn[$Key]) )    { $Drawn[$Key] = ""; }
694
+            if ( !isset($Drawn[$NodeID]) ) { $Drawn[$NodeID] = ""; }
695 695
 
696
-           if ( isset($this->Data[$NodeID]) && !isset($Drawn[$Key][$NodeID]) && !isset($Drawn[$NodeID][$Key]) )
696
+            if ( isset($this->Data[$NodeID]) && !isset($Drawn[$Key][$NodeID]) && !isset($Drawn[$NodeID][$Key]) )
697 697
             {
698
-             $Color = array("R"=>$this->Default["LinkR"],"G"=>$this->Default["LinkG"],"B"=>$this->Default["LinkB"],"Alpha"=>$this->Default["Alpha"]);
698
+                $Color = array("R"=>$this->Default["LinkR"],"G"=>$this->Default["LinkG"],"B"=>$this->Default["LinkB"],"Alpha"=>$this->Default["Alpha"]);
699 699
 
700
-             if ( $this->Links != "" )
701
-              {
702
-               if ( isset($this->Links[$Key][$NodeID]["R"]) )
700
+                if ( $this->Links != "" )
701
+                {
702
+                if ( isset($this->Links[$Key][$NodeID]["R"]) )
703 703
                 { $Color = array("R"=>$this->Links[$Key][$NodeID]["R"],"G"=>$this->Links[$Key][$NodeID]["G"],"B"=>$this->Links[$Key][$NodeID]["B"],"Alpha"=>$this->Links[$Key][$NodeID]["Alpha"]); }
704 704
 
705
-               if ( isset($this->Links[$Key][$NodeID]["Ticks"]) )
706
-                 { $Color["Ticks"] = $this->Links[$Key][$NodeID]["Ticks"]; }
707
-              }
705
+                if ( isset($this->Links[$Key][$NodeID]["Ticks"]) )
706
+                    { $Color["Ticks"] = $this->Links[$Key][$NodeID]["Ticks"]; }
707
+                }
708 708
 
709
-             $X2 = $this->Data[$NodeID]["X"];
710
-             $Y2 = $this->Data[$NodeID]["Y"];
711
-             $this->pChartObject->drawLine($X,$Y,$X2,$Y2,$Color);
712
-             $Drawn[$Key][$NodeID] = TRUE;
709
+                $X2 = $this->Data[$NodeID]["X"];
710
+                $Y2 = $this->Data[$NodeID]["Y"];
711
+                $this->pChartObject->drawLine($X,$Y,$X2,$Y2,$Color);
712
+                $Drawn[$Key][$NodeID] = TRUE;
713 713
 
714
-             if ( isset($this->Links) && $this->Links != "" )
715
-              {
716
-               if ( isset($this->Links[$Key][$NodeID]["Name"]) || isset($this->Links[$NodeID][$Key]["Name"]) )
714
+                if ( isset($this->Links) && $this->Links != "" )
715
+                {
716
+                if ( isset($this->Links[$Key][$NodeID]["Name"]) || isset($this->Links[$NodeID][$Key]["Name"]) )
717 717
                 {
718
-                 $Name  = isset($this->Links[$Key][$NodeID]["Name"]) ? $this->Links[$Key][$NodeID]["Name"] : $this->Links[$NodeID][$Key]["Name"];
719
-                 $TxtX  = ($X2 - $X)/2 + $X;
720
-                 $TxtY  = ($Y2 - $Y)/2 + $Y;
721
-
722
-                 if ( $X <= $X2 )
723
-                  $Angle = (360-$this->getAngle($X,$Y,$X2,$Y2)) % 360;
724
-                 else
725
-                  $Angle = (360-$this->getAngle($X2,$Y2,$X,$Y)) % 360;
726
-
727
-                 $Settings          = $Color;
728
-                 $Settings["Angle"] = $Angle;
729
-                 $Settings["Align"] = TEXT_ALIGN_BOTTOMMIDDLE;
730
-                 $this->pChartObject->drawText($TxtX,$TxtY,$Name,$Settings);
718
+                    $Name  = isset($this->Links[$Key][$NodeID]["Name"]) ? $this->Links[$Key][$NodeID]["Name"] : $this->Links[$NodeID][$Key]["Name"];
719
+                    $TxtX  = ($X2 - $X)/2 + $X;
720
+                    $TxtY  = ($Y2 - $Y)/2 + $Y;
721
+
722
+                    if ( $X <= $X2 )
723
+                    $Angle = (360-$this->getAngle($X,$Y,$X2,$Y2)) % 360;
724
+                    else
725
+                    $Angle = (360-$this->getAngle($X2,$Y2,$X,$Y)) % 360;
726
+
727
+                    $Settings          = $Color;
728
+                    $Settings["Angle"] = $Angle;
729
+                    $Settings["Align"] = TEXT_ALIGN_BOTTOMMIDDLE;
730
+                    $this->pChartObject->drawText($TxtX,$TxtY,$Name,$Settings);
731 731
                 }
732
-              }
732
+                }
733
+            }
733 734
             }
734
-          }
735 735
         }
736
-      }
736
+        }
737 737
 
738
-     /* Draw the quiet zones */
739
-     if ( $DrawQuietZone )
740
-      {
741
-       foreach($this->Data as $Key => $Settings)
738
+        /* Draw the quiet zones */
739
+        if ( $DrawQuietZone )
740
+        {
741
+        foreach($this->Data as $Key => $Settings)
742 742
         {
743
-         $X	 = $Settings["X"];
744
-         $Y	 = $Settings["Y"];
745
-         $FreeZone = $Settings["FreeZone"];
743
+            $X	 = $Settings["X"];
744
+            $Y	 = $Settings["Y"];
745
+            $FreeZone = $Settings["FreeZone"];
746 746
 
747
-         $this->pChartObject->drawFilledCircle($X,$Y,$FreeZone,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>2));
747
+            $this->pChartObject->drawFilledCircle($X,$Y,$FreeZone,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>2));
748
+        }
748 749
         }
749
-      }
750 750
 
751 751
 
752
-     /* Draw the nodes */
753
-     foreach($this->Data as $Key => $Settings)
754
-      {
755
-       $X	 = $Settings["X"];
756
-       $Y	 = $Settings["Y"];
757
-       $Name	 = $Settings["Name"];
758
-       $FreeZone = $Settings["FreeZone"];
759
-       $Shape    = $Settings["Shape"];
760
-       $Size     = $Settings["Size"];
752
+        /* Draw the nodes */
753
+        foreach($this->Data as $Key => $Settings)
754
+        {
755
+        $X	 = $Settings["X"];
756
+        $Y	 = $Settings["Y"];
757
+        $Name	 = $Settings["Name"];
758
+        $FreeZone = $Settings["FreeZone"];
759
+        $Shape    = $Settings["Shape"];
760
+        $Size     = $Settings["Size"];
761 761
 
762
-       $Color	 = array("R"=>$Settings["R"],"G"=>$Settings["G"],"B"=>$Settings["B"],"Alpha"=>$Settings["Alpha"],"BorderR"=>$Settings["BorderR"],"BorderG"=>$Settings["BorderG"],"BorderB"=>$Settings["BorderB"],"BorderApha"=>$Settings["BorderAlpha"]);
762
+        $Color	 = array("R"=>$Settings["R"],"G"=>$Settings["G"],"B"=>$Settings["B"],"Alpha"=>$Settings["Alpha"],"BorderR"=>$Settings["BorderR"],"BorderG"=>$Settings["BorderG"],"BorderB"=>$Settings["BorderB"],"BorderApha"=>$Settings["BorderAlpha"]);
763 763
 
764
-       if ( $Shape == NODE_SHAPE_CIRCLE )
764
+        if ( $Shape == NODE_SHAPE_CIRCLE )
765 765
         {
766
-         $this->pChartObject->drawFilledCircle($X,$Y,$Size,$Color);
766
+            $this->pChartObject->drawFilledCircle($X,$Y,$Size,$Color);
767 767
         }
768
-       elseif ( $Shape == NODE_SHAPE_TRIANGLE )
768
+        elseif ( $Shape == NODE_SHAPE_TRIANGLE )
769 769
         {
770
-         $Points = "";
771
-         $Points[] = cos(deg2rad(270)) * $Size + $X; $Points[] = sin(deg2rad(270)) * $Size + $Y;
772
-         $Points[] = cos(deg2rad(45)) * $Size + $X;  $Points[] = sin(deg2rad(45)) * $Size + $Y;
773
-         $Points[] = cos(deg2rad(135)) * $Size + $X; $Points[] = sin(deg2rad(135)) * $Size + $Y;
774
-         $this->pChartObject->drawPolygon($Points,$Color);
770
+            $Points = "";
771
+            $Points[] = cos(deg2rad(270)) * $Size + $X; $Points[] = sin(deg2rad(270)) * $Size + $Y;
772
+            $Points[] = cos(deg2rad(45)) * $Size + $X;  $Points[] = sin(deg2rad(45)) * $Size + $Y;
773
+            $Points[] = cos(deg2rad(135)) * $Size + $X; $Points[] = sin(deg2rad(135)) * $Size + $Y;
774
+            $this->pChartObject->drawPolygon($Points,$Color);
775 775
         }
776
-       elseif ( $Shape == NODE_SHAPE_SQUARE )
776
+        elseif ( $Shape == NODE_SHAPE_SQUARE )
777 777
         {
778
-         $Offset = $Size/2; $Size = $Size / 2;
779
-         $this->pChartObject->drawFilledRectangle($X-$Offset,$Y-$Offset,$X+$Offset,$Y+$Offset,$Color);
778
+            $Offset = $Size/2; $Size = $Size / 2;
779
+            $this->pChartObject->drawFilledRectangle($X-$Offset,$Y-$Offset,$X+$Offset,$Y+$Offset,$Color);
780 780
         }
781 781
 
782
-       if ( $Name != "" )
782
+        if ( $Name != "" )
783 783
         {
784
-         $LabelOptions = array("R"=>$this->Labels["R"],"G"=>$this->Labels["G"],"B"=>$this->Labels["B"],"Alpha"=>$this->Labels["Alpha"]);
784
+            $LabelOptions = array("R"=>$this->Labels["R"],"G"=>$this->Labels["G"],"B"=>$this->Labels["B"],"Alpha"=>$this->Labels["Alpha"]);
785 785
 
786
-         if ( $this->Labels["Type"] == LABEL_LIGHT )
787
-          {
788
-           $LabelOptions["Align"] = TEXT_ALIGN_BOTTOMLEFT;
789
-           $this->pChartObject->drawText($X,$Y,$Name,$LabelOptions);
790
-          }
791
-         elseif ( $this->Labels["Type"] == LABEL_CLASSIC )
792
-          {
793
-           $LabelOptions["Align"]         = TEXT_ALIGN_TOPMIDDLE;
794
-           $LabelOptions["DrawBox"]       = TRUE;
795
-           $LabelOptions["BoxAlpha"]      = 50;
796
-           $LabelOptions["BorderOffset"]  = 4;
797
-           $LabelOptions["RoundedRadius"] = 3;
798
-           $LabelOptions["BoxRounded"]    = TRUE;
799
-           $LabelOptions["NoShadow"]      = TRUE;
800
-
801
-           $this->pChartObject->drawText($X,$Y+$Size+$TextPadding,$Name,$LabelOptions);
802
-          }
786
+            if ( $this->Labels["Type"] == LABEL_LIGHT )
787
+            {
788
+            $LabelOptions["Align"] = TEXT_ALIGN_BOTTOMLEFT;
789
+            $this->pChartObject->drawText($X,$Y,$Name,$LabelOptions);
790
+            }
791
+            elseif ( $this->Labels["Type"] == LABEL_CLASSIC )
792
+            {
793
+            $LabelOptions["Align"]         = TEXT_ALIGN_TOPMIDDLE;
794
+            $LabelOptions["DrawBox"]       = TRUE;
795
+            $LabelOptions["BoxAlpha"]      = 50;
796
+            $LabelOptions["BorderOffset"]  = 4;
797
+            $LabelOptions["RoundedRadius"] = 3;
798
+            $LabelOptions["BoxRounded"]    = TRUE;
799
+            $LabelOptions["NoShadow"]      = TRUE;
800
+
801
+            $this->pChartObject->drawText($X,$Y+$Size+$TextPadding,$Name,$LabelOptions);
802
+            }
803
+        }
803 804
         }
804
-      }
805 805
 
806
-     /* Draw the vectors */
807
-     if ( $DrawVectors )
808
-      {
809
-       foreach($this->Data as $Key => $Settings)
806
+        /* Draw the vectors */
807
+        if ( $DrawVectors )
810 808
         {
811
-         $X1 = $Settings["X"];
812
-         $Y1 = $Settings["Y"];
809
+        foreach($this->Data as $Key => $Settings)
810
+        {
811
+            $X1 = $Settings["X"];
812
+            $Y1 = $Settings["Y"];
813 813
 
814
-         if ( isset($Settings["Vectors"]) && $Settings["Type"] != NODE_TYPE_CENTRAL )
815
-          {
816
-           foreach($Settings["Vectors"] as $ID => $Vector)
814
+            if ( isset($Settings["Vectors"]) && $Settings["Type"] != NODE_TYPE_CENTRAL )
815
+            {
816
+            foreach($Settings["Vectors"] as $ID => $Vector)
817 817
             {
818
-             $Type  = $Vector["Type"];
819
-             $Force = $Vector["Force"];
820
-             $Angle = $Vector["Angle"];
821
-             $Factor = $Type == "A" ? $this->MagneticForceA : $this->MagneticForceR;
822
-             $Color  = $Type == "A" ? array("FillR"=>255,"FillG"=>0,"FillB"=>0) : array("FillR"=>0,"FillG"=>255,"FillB"=>0);
818
+                $Type  = $Vector["Type"];
819
+                $Force = $Vector["Force"];
820
+                $Angle = $Vector["Angle"];
821
+                $Factor = $Type == "A" ? $this->MagneticForceA : $this->MagneticForceR;
822
+                $Color  = $Type == "A" ? array("FillR"=>255,"FillG"=>0,"FillB"=>0) : array("FillR"=>0,"FillG"=>255,"FillB"=>0);
823 823
 
824
-             $X2 = cos(deg2rad($Angle)) * $Force * $Factor + $X1;
825
-             $Y2 = sin(deg2rad($Angle)) * $Force * $Factor + $Y1;
824
+                $X2 = cos(deg2rad($Angle)) * $Force * $Factor + $X1;
825
+                $Y2 = sin(deg2rad($Angle)) * $Force * $Factor + $Y1;
826 826
 
827
-             $this->pChartObject->drawArrow($X1,$Y1,$X2,$Y2,$Color);
827
+                $this->pChartObject->drawArrow($X1,$Y1,$X2,$Y2,$Color);
828 828
             }
829
-          }
829
+            }
830
+        }
830 831
         }
831
-      }
832 832
 
833
-     return(array("Pass"=>$Jobs,"Conflicts"=>$Conflicts));
833
+        return(array("Pass"=>$Jobs,"Conflicts"=>$Conflicts));
834 834
     }
835 835
 
836
-   /* Return the distance between two points */
837
-   function getDistance($X1,$Y1,$X2,$Y2)
836
+    /* Return the distance between two points */
837
+    function getDistance($X1,$Y1,$X2,$Y2)
838 838
     { return (sqrt(($X2-$X1)*($X2-$X1)+($Y2-$Y1)*($Y2-$Y1))); }
839 839
 
840
-   /* Return the angle made by a line and the X axis */
841
-   function getAngle($X1,$Y1,$X2,$Y2)
840
+    /* Return the angle made by a line and the X axis */
841
+    function getAngle($X1,$Y1,$X2,$Y2)
842 842
     {
843
-     $Opposite = $Y2 - $Y1; $Adjacent = $X2 - $X1;$Angle = rad2deg(atan2($Opposite,$Adjacent));
844
-     if ($Angle > 0) { return($Angle); } else { return(360-abs($Angle)); }
843
+        $Opposite = $Y2 - $Y1; $Adjacent = $X2 - $X1;$Angle = rad2deg(atan2($Opposite,$Adjacent));
844
+        if ($Angle > 0) { return($Angle); } else { return(360-abs($Angle)); }
845 845
     }
846 846
 
847
-   function intersect($X1,$Y1,$X2,$Y2,$X3,$Y3,$X4,$Y4)
847
+    function intersect($X1,$Y1,$X2,$Y2,$X3,$Y3,$X4,$Y4)
848 848
     {
849
-     $A = (($X3 * $Y4 - $X4 * $Y3) * ($X1 - $X2) - ($X1 * $Y2 - $X2 * $Y1) * ($X3 - $X4));
850
-     $B = (($Y1 - $Y2) * ($X3 - $X4) - ($Y3 - $Y4) * ($X1 - $X2));
849
+        $A = (($X3 * $Y4 - $X4 * $Y3) * ($X1 - $X2) - ($X1 * $Y2 - $X2 * $Y1) * ($X3 - $X4));
850
+        $B = (($Y1 - $Y2) * ($X3 - $X4) - ($Y3 - $Y4) * ($X1 - $X2));
851 851
 
852
-     if ( $B == 0 ) { return(FALSE); }
853
-     $Xi = $A / $B;
852
+        if ( $B == 0 ) { return(FALSE); }
853
+        $Xi = $A / $B;
854 854
 
855
-     $C = ($X1 - $X2);
856
-     if ( $C == 0 ) { return(FALSE); }
857
-     $Yi = $Xi * (($Y1 - $Y2)/$C) + (($X1 * $Y2 - $X2 * $Y1)/$C);
855
+        $C = ($X1 - $X2);
856
+        if ( $C == 0 ) { return(FALSE); }
857
+        $Yi = $Xi * (($Y1 - $Y2)/$C) + (($X1 * $Y2 - $X2 * $Y1)/$C);
858 858
 
859
-     if ( $Xi >= min($X1,$X2) && $Xi >= min($X3,$X4) && $Xi <= max($X1,$X2) && $Xi <= max($X3,$X4))
860
-      {
861
-       if ( $Yi >= min($Y1,$Y2) && $Yi >= min($Y3,$Y4) && $Yi <= max($Y1,$Y2) && $Yi <= max($Y3,$Y4))
859
+        if ( $Xi >= min($X1,$X2) && $Xi >= min($X3,$X4) && $Xi <= max($X1,$X2) && $Xi <= max($X3,$X4))
860
+        {
861
+        if ( $Yi >= min($Y1,$Y2) && $Yi >= min($Y3,$Y4) && $Yi <= max($Y1,$Y2) && $Yi <= max($Y3,$Y4))
862 862
         { return(TRUE); }
863
-      }
863
+        }
864 864
 
865
-      return(FALSE);   
865
+        return(FALSE);   
866
+    }
866 867
     }
867
-  }
868 868
 ?>
869 869
\ No newline at end of file
Please login to merge, or discard this patch.