@@ -9,45 +9,45 @@ discard block |
||
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 |
||
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 |
||
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 | } |
@@ -42,8 +42,7 @@ |
||
42 | 42 | if (is_array($element)) { |
43 | 43 | show($element); |
44 | 44 | return drupal_render($element); |
45 | - } |
|
46 | - else { |
|
45 | + } else { |
|
47 | 46 | // Safe-guard for inappropriate use of render() on flat variables: return |
48 | 47 | // the variable as-is. |
49 | 48 | return $element; |
@@ -131,8 +131,7 @@ discard block |
||
131 | 131 | if ($comment->uid == 0 || strlen($comment->name) == 0) { |
132 | 132 | // @see user_validate_name(). !'0' === TRUE. |
133 | 133 | $comment_document->ss_name = '0'; |
134 | - } |
|
135 | - else { |
|
134 | + } else { |
|
136 | 135 | $comment_document->ss_name = $comment->name; |
137 | 136 | // We want the name to be searchable for keywords. |
138 | 137 | $comment_document->tos_name = $comment->name; |
@@ -318,8 +317,7 @@ discard block |
||
318 | 317 | $solr->deleteByQuery($query); |
319 | 318 | // Log the query used for deletion. |
320 | 319 | watchdog('Apache Solr', 'Deleted documents from index with query @query', array('@query' => $query), WATCHDOG_INFO); |
321 | - } |
|
322 | - catch (Exception $e) { |
|
320 | + } catch (Exception $e) { |
|
323 | 321 | watchdog('Apache Solr', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR); |
324 | 322 | return FALSE; |
325 | 323 | }// try |
@@ -376,8 +374,7 @@ discard block |
||
376 | 374 | $solr->deleteByQuery($query); |
377 | 375 | // Log the query used for deletion. |
378 | 376 | watchdog('Apache Solr', 'Deleted documents from index with query @query', array('@query' => $query), WATCHDOG_INFO); |
379 | - } |
|
380 | - catch (Exception $e) { |
|
377 | + } catch (Exception $e) { |
|
381 | 378 | watchdog('Apache Solr', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR); |
382 | 379 | return FALSE; |
383 | 380 | }// try |
@@ -14,19 +14,19 @@ discard block |
||
14 | 14 | * Implementation of hook_menu() |
15 | 15 | */ |
16 | 16 | function boinc_solr_comments_menu() { |
17 | - $items = array(); |
|
18 | - $base_path = 'admin/settings/apachesolr/indexcomments'; |
|
19 | - $items[$base_path] = array( |
|
20 | - 'title' => 'Index Comments', |
|
21 | - 'description' => 'Administer Indexing of Comments', |
|
22 | - 'page callback' => 'drupal_get_form', |
|
23 | - 'page arguments' => array('boinc_solr_comments_form'), |
|
24 | - 'access arguments' => array('administer search'), |
|
25 | - 'file' => 'boinc_solr_comments.admin.inc', |
|
26 | - 'weight' => '10', |
|
27 | - ); |
|
28 | - |
|
29 | - return $items; |
|
17 | + $items = array(); |
|
18 | + $base_path = 'admin/settings/apachesolr/indexcomments'; |
|
19 | + $items[$base_path] = array( |
|
20 | + 'title' => 'Index Comments', |
|
21 | + 'description' => 'Administer Indexing of Comments', |
|
22 | + 'page callback' => 'drupal_get_form', |
|
23 | + 'page arguments' => array('boinc_solr_comments_form'), |
|
24 | + 'access arguments' => array('administer search'), |
|
25 | + 'file' => 'boinc_solr_comments.admin.inc', |
|
26 | + 'weight' => '10', |
|
27 | + ); |
|
28 | + |
|
29 | + return $items; |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | |
@@ -58,11 +58,11 @@ discard block |
||
58 | 58 | * Environment ID for apache solr. |
59 | 59 | */ |
60 | 60 | function boinc_solr_comments_apachesolr_index_documents_alter(array &$documents, $entity, $entity_type, $env_id) { |
61 | - $comdocs = array(); |
|
61 | + $comdocs = array(); |
|
62 | 62 | |
63 | - // Array of node types that will have comments indexed. |
|
64 | - $node_types = variable_get('boinc_solr_comments_nodetypes', ''); |
|
65 | - if (empty($node_types)) { |
|
63 | + // Array of node types that will have comments indexed. |
|
64 | + $node_types = variable_get('boinc_solr_comments_nodetypes', ''); |
|
65 | + if (empty($node_types)) { |
|
66 | 66 | // If the variable has not been set, then by default index |
67 | 67 | // comments for all known node types. |
68 | 68 | $node_types = array( |
@@ -72,28 +72,28 @@ discard block |
||
72 | 72 | 'story' => 'story', |
73 | 73 | 'team_forum' => 'team_forum', |
74 | 74 | ); |
75 | - } |
|
75 | + } |
|
76 | 76 | |
77 | - // Loop over all documents and alter: |
|
78 | - foreach ($documents as $document) { |
|
77 | + // Loop over all documents and alter: |
|
78 | + foreach ($documents as $document) { |
|
79 | 79 | //dd($document, "index documents alter - document"); |
80 | 80 | |
81 | 81 | $to_process = ( array_key_exists($document->bundle, $node_types) AND $node_types[$document->bundle] ); |
82 | 82 | if ( $document->entity_type=='node' AND $to_process) { |
83 | 83 | |
84 | - // Remove ts_comments if present. |
|
85 | - if (isset($document->ts_comments)) { |
|
84 | + // Remove ts_comments if present. |
|
85 | + if (isset($document->ts_comments)) { |
|
86 | 86 | unset($document->ts_comments); |
87 | - } |
|
88 | - // Node information. |
|
89 | - $nid = $document->entity_id; |
|
90 | - $node = node_load($nid); |
|
87 | + } |
|
88 | + // Node information. |
|
89 | + $nid = $document->entity_id; |
|
90 | + $node = node_load($nid); |
|
91 | 91 | |
92 | - // Query database for comments of node. Only return comments |
|
93 | - // with status 0 (0 is published for comments). |
|
94 | - $sql = 'SELECT cid from {comments} WHERE nid = %d AND status = 0 ORDER by timestamp DESC'; |
|
95 | - $resource = db_query($sql, $nid); |
|
96 | - while ($row = db_fetch_array($resource)) { |
|
92 | + // Query database for comments of node. Only return comments |
|
93 | + // with status 0 (0 is published for comments). |
|
94 | + $sql = 'SELECT cid from {comments} WHERE nid = %d AND status = 0 ORDER by timestamp DESC'; |
|
95 | + $resource = db_query($sql, $nid); |
|
96 | + while ($row = db_fetch_array($resource)) { |
|
97 | 97 | // Load the comment from cid. |
98 | 98 | $comment = _comment_load($row['cid']); |
99 | 99 | |
@@ -116,10 +116,10 @@ discard block |
||
116 | 116 | // Comment object has no language |
117 | 117 | $comment_document->ss_language = 'und'; |
118 | 118 | if (function_exists('drupal_get_path_alias')) { |
119 | - $output = drupal_get_path_alias($comment_document->path, NULL); |
|
120 | - if ($output && $output != $document->path) { |
|
119 | + $output = drupal_get_path_alias($comment_document->path, NULL); |
|
120 | + if ($output && $output != $document->path) { |
|
121 | 121 | $comment_document->path_alias = $output; |
122 | - } |
|
122 | + } |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | // Code derived from apachesolr_index_node_solr_document |
@@ -129,13 +129,13 @@ discard block |
||
129 | 129 | |
130 | 130 | // Author information |
131 | 131 | if ($comment->uid == 0 || strlen($comment->name) == 0) { |
132 | - // @see user_validate_name(). !'0' === TRUE. |
|
133 | - $comment_document->ss_name = '0'; |
|
132 | + // @see user_validate_name(). !'0' === TRUE. |
|
133 | + $comment_document->ss_name = '0'; |
|
134 | 134 | } |
135 | 135 | else { |
136 | - $comment_document->ss_name = $comment->name; |
|
137 | - // We want the name to be searchable for keywords. |
|
138 | - $comment_document->tos_name = $comment->name; |
|
136 | + $comment_document->ss_name = $comment->name; |
|
137 | + // We want the name to be searchable for keywords. |
|
138 | + $comment_document->tos_name = $comment->name; |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | // Index formatted username so it can be searched and sorted |
@@ -157,59 +157,59 @@ discard block |
||
157 | 157 | // Unset the following fields (if set) that don't make sense |
158 | 158 | // for a comment. |
159 | 159 | if (isset($comment_document->bs_sticky)) { |
160 | - unset($comment_document->bs_sticky); |
|
160 | + unset($comment_document->bs_sticky); |
|
161 | 161 | } |
162 | 162 | if (isset($comment_document->bs_promote)) { |
163 | - unset($comment_document->bs_promote); |
|
163 | + unset($comment_document->bs_promote); |
|
164 | 164 | } |
165 | 165 | if (isset($comment_document->is_tnid)) { |
166 | - unset($comment_document->is_tnid); |
|
166 | + unset($comment_document->is_tnid); |
|
167 | 167 | } |
168 | 168 | if (isset($comment_document->bs_translate)) { |
169 | - unset($comment_document->bs_translate); |
|
169 | + unset($comment_document->bs_translate); |
|
170 | 170 | } |
171 | 171 | if (isset($comment_document->ts_last_comment_timestamp)) { |
172 | - unset($comment_document->ts_last_comment_timestamp); |
|
172 | + unset($comment_document->ts_last_comment_timestamp); |
|
173 | 173 | } |
174 | 174 | if (isset($comment_document->ds_last_comment_or_change)) { |
175 | - unset($comment_document->ds_last_comment_or_change); |
|
175 | + unset($comment_document->ds_last_comment_or_change); |
|
176 | 176 | } |
177 | 177 | if (isset($comment_document->is_comment_count)) { |
178 | - unset($comment_document->is_comment_count); |
|
178 | + unset($comment_document->is_comment_count); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | // Loop over fields in document and copy relevant values into |
182 | 182 | // comment_document. |
183 | 183 | foreach ($document as $fieldName => $fieldValue) { |
184 | 184 | |
185 | - // Copy over fields [im_taxonomy_vid_1], [tid], [im_vid_1], |
|
186 | - // [im_vid_Forums], [tm_vid_1_names] |
|
187 | - if ( ( preg_match('/tid/', $fieldName) OR preg_match('/vid/', $fieldName) ) AND is_array($fieldValue) ) { |
|
185 | + // Copy over fields [im_taxonomy_vid_1], [tid], [im_vid_1], |
|
186 | + // [im_vid_Forums], [tm_vid_1_names] |
|
187 | + if ( ( preg_match('/tid/', $fieldName) OR preg_match('/vid/', $fieldName) ) AND is_array($fieldValue) ) { |
|
188 | 188 | foreach ($fieldValue as $subkey => $subvalue) { |
189 | - $comment_document->addField($fieldName, $subvalue); |
|
189 | + $comment_document->addField($fieldName, $subvalue); |
|
190 | 190 | } |
191 | - }// if preg_match |
|
191 | + }// if preg_match |
|
192 | 192 | |
193 | - // Set the access keys so this module will work with |
|
194 | - // apachesolr_access. |
|
195 | - if (module_exists('apachesolr_access')) { |
|
193 | + // Set the access keys so this module will work with |
|
194 | + // apachesolr_access. |
|
195 | + if (module_exists('apachesolr_access')) { |
|
196 | 196 | if (preg_match('/^access/', $fieldName) AND is_array($fieldValue)) { |
197 | - foreach ($fieldValue as $subkey => $subvalue) { |
|
197 | + foreach ($fieldValue as $subkey => $subvalue) { |
|
198 | 198 | $comment_document->addField($fieldName, $subvalue); |
199 | - } |
|
199 | + } |
|
200 | 200 | }// if preg_match |
201 | - }// if module_exist |
|
201 | + }// if module_exist |
|
202 | 202 | |
203 | 203 | }// foreach document |
204 | 204 | |
205 | 205 | $comdocs[] = $comment_document; |
206 | - }// while |
|
206 | + }// while |
|
207 | 207 | }// if entity_type=node |
208 | - }// documents |
|
208 | + }// documents |
|
209 | 209 | |
210 | - // Merge the comment documents with the input documents array. These |
|
211 | - // documents will now be added to the Solr search index. |
|
212 | - $documents = array_merge($documents, $comdocs); |
|
210 | + // Merge the comment documents with the input documents array. These |
|
211 | + // documents will now be added to the Solr search index. |
|
212 | + $documents = array_merge($documents, $comdocs); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
@@ -225,19 +225,19 @@ discard block |
||
225 | 225 | * The Solr query used for the search. |
226 | 226 | */ |
227 | 227 | function boinc_solr_comments_apachesolr_process_results(&$results, DrupalSolrQueryInterface $query) { |
228 | - //dpm($query->getSolrParams(), "process_results query getSolrParams"); |
|
229 | - foreach($results as $id => $result) { |
|
228 | + //dpm($query->getSolrParams(), "process_results query getSolrParams"); |
|
229 | + foreach($results as $id => $result) { |
|
230 | 230 | if ($result['entity_type']=='comment') { |
231 | 231 | $results[$id]['type'] = 'Comment'; |
232 | 232 | $results[$id]['date'] = $result['fields']['changed']; |
233 | 233 | if (isset($result['fields']['is_uid'])) { |
234 | - $uid = $result['fields']['is_uid']; |
|
235 | - $results[$id]['uid'] = $uid; |
|
236 | - $results[$id]['user'] = theme('username', user_load($uid)); |
|
234 | + $uid = $result['fields']['is_uid']; |
|
235 | + $results[$id]['uid'] = $uid; |
|
236 | + $results[$id]['user'] = theme('username', user_load($uid)); |
|
237 | 237 | } |
238 | 238 | } //if result entity_type == comment |
239 | - }// foreach $result |
|
240 | - //dpm($results, "process_results array_results"); |
|
239 | + }// foreach $result |
|
240 | + //dpm($results, "process_results array_results"); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
@@ -251,8 +251,8 @@ discard block |
||
251 | 251 | * The Solr query used for the search. |
252 | 252 | */ |
253 | 253 | function boinc_solr_comments_apachesolr_query_alter($query) { |
254 | - // Add custom field to query results |
|
255 | - $query->addParam('fl','tos_content_extra'); |
|
254 | + // Add custom field to query results |
|
255 | + $query->addParam('fl','tos_content_extra'); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * |
@@ -265,9 +265,9 @@ discard block |
||
265 | 265 | * |
266 | 266 | */ |
267 | 267 | function boinc_solr_comments_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { |
268 | - // Array of node types that will have comments indexed. |
|
269 | - $node_types = variable_get('boinc_solr_comments_nodetypes', ''); |
|
270 | - if (empty($node_types)) { |
|
268 | + // Array of node types that will have comments indexed. |
|
269 | + $node_types = variable_get('boinc_solr_comments_nodetypes', ''); |
|
270 | + if (empty($node_types)) { |
|
271 | 271 | // If the variable has not been set, then by default index |
272 | 272 | // comments for all known node types. |
273 | 273 | $node_types = array( |
@@ -277,16 +277,16 @@ discard block |
||
277 | 277 | 'story' => 'story', |
278 | 278 | 'team_forum' => 'team_forum', |
279 | 279 | ); |
280 | - } |
|
280 | + } |
|
281 | 281 | |
282 | - switch ($op) { |
|
282 | + switch ($op) { |
|
283 | 283 | case 'delete': |
284 | 284 | // Only call delete function on certain node types |
285 | 285 | if (in_array( $node->type, $node_types)) { |
286 | 286 | boinc_solr_comments_delete($node); |
287 | - } |
|
288 | - break; |
|
289 | - } //switch |
|
287 | + } |
|
288 | + break; |
|
289 | + } //switch |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | |
@@ -303,30 +303,30 @@ discard block |
||
303 | 303 | * Returns TRUE if the comment was deleted, otherwise return FALSE. |
304 | 304 | */ |
305 | 305 | function boinc_solr_comments_delete($node) { |
306 | - // Load the Solr environment. |
|
307 | - $env_id = apachesolr_default_environment(); |
|
308 | - // Check to see if Solr is read-only. |
|
309 | - if (apachesolr_environment_variable_get($env_id, 'apachesolr_read_only', APACHESOLR_READ_WRITE) == APACHESOLR_READ_ONLY) { |
|
306 | + // Load the Solr environment. |
|
307 | + $env_id = apachesolr_default_environment(); |
|
308 | + // Check to see if Solr is read-only. |
|
309 | + if (apachesolr_environment_variable_get($env_id, 'apachesolr_read_only', APACHESOLR_READ_WRITE) == APACHESOLR_READ_ONLY) { |
|
310 | 310 | return FALSE; |
311 | - } |
|
311 | + } |
|
312 | 312 | |
313 | - // Code derived from apachesolr_index_delete_entity_from_index |
|
314 | - try { |
|
313 | + // Code derived from apachesolr_index_delete_entity_from_index |
|
314 | + try { |
|
315 | 315 | $solr = apachesolr_get_solr($env_id); |
316 | 316 | // Custom query to find all comments with parent nid of the node bing deleted. |
317 | 317 | $query = "entity_type:comment AND tos_content_extra:" . $node->nid; |
318 | 318 | $solr->deleteByQuery($query); |
319 | 319 | // Log the query used for deletion. |
320 | 320 | watchdog('Apache Solr', 'Deleted documents from index with query @query', array('@query' => $query), WATCHDOG_INFO); |
321 | - } |
|
322 | - catch (Exception $e) { |
|
323 | - watchdog('Apache Solr', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR); |
|
324 | - return FALSE; |
|
325 | - }// try |
|
326 | - |
|
327 | - // all deletions sucessful |
|
328 | - apachesolr_set_last_index_updated($env_id, APACHESOLR_REQUEST_TIME); |
|
329 | - return TRUE; |
|
321 | + } |
|
322 | + catch (Exception $e) { |
|
323 | + watchdog('Apache Solr', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR); |
|
324 | + return FALSE; |
|
325 | + }// try |
|
326 | + |
|
327 | + // all deletions sucessful |
|
328 | + apachesolr_set_last_index_updated($env_id, APACHESOLR_REQUEST_TIME); |
|
329 | + return TRUE; |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | /** |
@@ -334,15 +334,15 @@ discard block |
||
334 | 334 | * |
335 | 335 | */ |
336 | 336 | function boinc_solr_comments_comment(&$a1, $op) { |
337 | - switch ($op) { |
|
337 | + switch ($op) { |
|
338 | 338 | case 'view': |
339 | 339 | case 'update': |
340 | 340 | break; |
341 | 341 | case 'delete': |
342 | 342 | // $a1 should be a comment object |
343 | 343 | boinc_solr_comments_deletecomment($a1); |
344 | - break; |
|
345 | - }// switch |
|
344 | + break; |
|
345 | + }// switch |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | /** |
@@ -358,16 +358,16 @@ discard block |
||
358 | 358 | * Returns TRUE if the comment was deleted, otherwise return FALSE. |
359 | 359 | */ |
360 | 360 | function boinc_solr_comments_deletecomment($comment) { |
361 | - // Load the Solr environment. |
|
362 | - $env_id = apachesolr_default_environment(); |
|
363 | - // Check to see if Solr is read-only. |
|
364 | - if (apachesolr_environment_variable_get($env_id, 'apachesolr_read_only', APACHESOLR_READ_WRITE) == APACHESOLR_READ_ONLY) { |
|
361 | + // Load the Solr environment. |
|
362 | + $env_id = apachesolr_default_environment(); |
|
363 | + // Check to see if Solr is read-only. |
|
364 | + if (apachesolr_environment_variable_get($env_id, 'apachesolr_read_only', APACHESOLR_READ_WRITE) == APACHESOLR_READ_ONLY) { |
|
365 | 365 | return FALSE; |
366 | - } |
|
367 | - //dd($comment->cid, "delete - nid begin"); |
|
366 | + } |
|
367 | + //dd($comment->cid, "delete - nid begin"); |
|
368 | 368 | |
369 | - // Code derived from apachesolr_index_delete_entity_from_index. |
|
370 | - try { |
|
369 | + // Code derived from apachesolr_index_delete_entity_from_index. |
|
370 | + try { |
|
371 | 371 | $solr = apachesolr_get_solr($env_id); |
372 | 372 | $entity_id = $comment->cid; |
373 | 373 | $entity_type = 'comment'; |
@@ -377,14 +377,14 @@ discard block |
||
377 | 377 | // Log the query used for deletion. |
378 | 378 | watchdog('Apache Solr', 'Deleted documents from index with query @query', array('@query' => $query), WATCHDOG_INFO); |
379 | 379 | } |
380 | - catch (Exception $e) { |
|
380 | + catch (Exception $e) { |
|
381 | 381 | watchdog('Apache Solr', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR); |
382 | 382 | return FALSE; |
383 | - }// try |
|
383 | + }// try |
|
384 | 384 | |
385 | - // deletion sucessful |
|
386 | - apachesolr_set_last_index_updated($env_id, APACHESOLR_REQUEST_TIME); |
|
387 | - return TRUE; |
|
385 | + // deletion sucessful |
|
386 | + apachesolr_set_last_index_updated($env_id, APACHESOLR_REQUEST_TIME); |
|
387 | + return TRUE; |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | */ |
400 | 400 | |
401 | 401 | function boinc_solr_comments_enable() { |
402 | - drupal_set_message( bts('Warning: Your content <a href="@url">must be re-indexed</a> before Apache Solr will search comments.', array('@url' => url('admin/settings/apachesolr/index')), NULL, 'boinc:admin-solr-index-comments-message'), 'warning'); |
|
402 | + drupal_set_message( bts('Warning: Your content <a href="@url">must be re-indexed</a> before Apache Solr will search comments.', array('@url' => url('admin/settings/apachesolr/index')), NULL, 'boinc:admin-solr-index-comments-message'), 'warning'); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
@@ -410,12 +410,12 @@ discard block |
||
410 | 410 | * The comment to be published (unhidden). |
411 | 411 | */ |
412 | 412 | function boinc_solr_comments_publish($comment) { |
413 | - if ( ($comment->cid) AND ($comment->nid) ) { |
|
413 | + if ( ($comment->cid) AND ($comment->nid) ) { |
|
414 | 414 | $node = node_load($comment->nid); |
415 | 415 | // Tell Solr that the node has been updated, so the comment can be |
416 | 416 | // indexed. |
417 | 417 | apachesolr_entity_update($node, 'node'); |
418 | - } |
|
418 | + } |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | /** |
@@ -426,9 +426,9 @@ discard block |
||
426 | 426 | * The comment to be unpublished (hidden). |
427 | 427 | */ |
428 | 428 | function boinc_solr_comments_unpublish($comment) { |
429 | - if ( ($comment->cid) ) { |
|
429 | + if ( ($comment->cid) ) { |
|
430 | 430 | // Call the deletecomment function for hook comment. |
431 | 431 | boinc_solr_comments_deletecomment($comment); |
432 | - } |
|
432 | + } |
|
433 | 433 | } |
434 | 434 |
@@ -7,15 +7,15 @@ |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | class views_handler_argument_boincteam_id extends views_handler_argument_numeric { |
10 | - function construct() { |
|
10 | + function construct() { |
|
11 | 11 | parent::construct(); |
12 | - } |
|
12 | + } |
|
13 | 13 | |
14 | - function set_argument($arg) { |
|
14 | + function set_argument($arg) { |
|
15 | 15 | // When setting the ID argument, convert to BOINC ID |
16 | 16 | $id = is_numeric($arg) ? $arg : 0; |
17 | 17 | $boinc_id = db_result(db_query("SELECT team_id FROM {boincteam} WHERE nid = %d", $id)); |
18 | 18 | $this->argument = $boinc_id; |
19 | 19 | return $this->validate_arg($boinc_id); |
20 | - } |
|
20 | + } |
|
21 | 21 | } |
@@ -13,80 +13,80 @@ |
||
13 | 13 | */ |
14 | 14 | function boincteam_forum_views_data() { |
15 | 15 | |
16 | - // ----------------------------------------------------------------------------------------------- |
|
17 | - // Definition for team table |
|
18 | - // ----------------------------------------------------------------------------------------------- |
|
16 | + // ----------------------------------------------------------------------------------------------- |
|
17 | + // Definition for team table |
|
18 | + // ----------------------------------------------------------------------------------------------- |
|
19 | 19 | |
20 | - $data['boincteam_forum_node']['table']['group'] = t('BOINC'); |
|
20 | + $data['boincteam_forum_node']['table']['group'] = t('BOINC'); |
|
21 | 21 | |
22 | - $data['boincteam_forum_node']['table']['base'] = array( |
|
23 | - 'field' => 'nid', |
|
24 | - 'title' => t('BOINC team forum topic'), |
|
25 | - 'help' => t('Forum topics for a team'), |
|
26 | - ); |
|
22 | + $data['boincteam_forum_node']['table']['base'] = array( |
|
23 | + 'field' => 'nid', |
|
24 | + 'title' => t('BOINC team forum topic'), |
|
25 | + 'help' => t('Forum topics for a team'), |
|
26 | + ); |
|
27 | 27 | |
28 | - // Describe each of the individual fields in this table to Views. For |
|
29 | - // each field, you may define what field, sort, argument, and/or filter |
|
30 | - // handlers it supports. This will determine where in the Views interface you |
|
31 | - // may use the field. |
|
28 | + // Describe each of the individual fields in this table to Views. For |
|
29 | + // each field, you may define what field, sort, argument, and/or filter |
|
30 | + // handlers it supports. This will determine where in the Views interface you |
|
31 | + // may use the field. |
|
32 | 32 | |
33 | - // Primary keys allowed as arguments |
|
33 | + // Primary keys allowed as arguments |
|
34 | 34 | |
35 | - $data['boincteam_forum_node']['tfid'] = array( |
|
35 | + $data['boincteam_forum_node']['tfid'] = array( |
|
36 | 36 | 'title' => t('Team forum ID'), |
37 | 37 | 'help' => t('The ID of the team forum containing this topic.'), |
38 | 38 | 'field' => array( |
39 | - 'handler' => 'views_handler_field_numeric', |
|
40 | - 'click sortable' => TRUE |
|
39 | + 'handler' => 'views_handler_field_numeric', |
|
40 | + 'click sortable' => TRUE |
|
41 | 41 | ), |
42 | 42 | 'argument' => array( |
43 | - 'handler' => 'views_handler_argument_numeric', |
|
44 | - 'name field' => 'title', // the field to display in the summary. |
|
45 | - 'numeric' => TRUE, |
|
46 | - 'validate type' => 'id' |
|
43 | + 'handler' => 'views_handler_argument_numeric', |
|
44 | + 'name field' => 'title', // the field to display in the summary. |
|
45 | + 'numeric' => TRUE, |
|
46 | + 'validate type' => 'id' |
|
47 | 47 | ), |
48 | 48 | 'relationship' => array( |
49 | - 'base' => 'boincteam_forum', |
|
50 | - 'field' => 'tfid', |
|
51 | - 'handler' => 'views_handler_relationship', |
|
52 | - 'label' => t('Team Forum') |
|
49 | + 'base' => 'boincteam_forum', |
|
50 | + 'field' => 'tfid', |
|
51 | + 'handler' => 'views_handler_relationship', |
|
52 | + 'label' => t('Team Forum') |
|
53 | 53 | ), |
54 | 54 | 'filter' => array( |
55 | - 'handler' => 'views_handler_filter_numeric' |
|
55 | + 'handler' => 'views_handler_filter_numeric' |
|
56 | 56 | ), |
57 | 57 | 'sort' => array( |
58 | - 'handler' => 'views_handler_sort_numeric' |
|
58 | + 'handler' => 'views_handler_sort_numeric' |
|
59 | 59 | ) |
60 | - ); |
|
60 | + ); |
|
61 | 61 | |
62 | - // Foreign key fields |
|
62 | + // Foreign key fields |
|
63 | 63 | |
64 | - $data['boincteam_forum_node']['nid'] = array( |
|
64 | + $data['boincteam_forum_node']['nid'] = array( |
|
65 | 65 | 'title' => t('Team forum node'), |
66 | 66 | 'help' => t('The node containing the content of this team forum topic.'), |
67 | 67 | // This is a foreign key to the {node} table. When the view is configured |
68 | 68 | // with this relationship, all the fields for the related user node will be |
69 | 69 | // available. |
70 | 70 | 'relationship' => array( |
71 | - 'base' => 'node', |
|
72 | - 'field' => 'nid', |
|
73 | - 'handler' => 'views_handler_relationship', |
|
74 | - 'label' => t('Team Forum Topic Node') |
|
71 | + 'base' => 'node', |
|
72 | + 'field' => 'nid', |
|
73 | + 'handler' => 'views_handler_relationship', |
|
74 | + 'label' => t('Team Forum Topic Node') |
|
75 | 75 | ), |
76 | 76 | 'field' => array( |
77 | - 'handler' => 'views_handler_field_numeric', |
|
78 | - 'click sortable' => TRUE |
|
77 | + 'handler' => 'views_handler_field_numeric', |
|
78 | + 'click sortable' => TRUE |
|
79 | 79 | ), |
80 | 80 | 'filter' => array( |
81 | - 'handler' => 'views_handler_filter_numeric' |
|
81 | + 'handler' => 'views_handler_filter_numeric' |
|
82 | 82 | ), |
83 | 83 | 'sort' => array( |
84 | - 'handler' => 'views_handler_sort_numeric' |
|
84 | + 'handler' => 'views_handler_sort_numeric' |
|
85 | 85 | ) |
86 | - ); |
|
86 | + ); |
|
87 | 87 | |
88 | - // Descriptions of general fields (alphabetized) |
|
89 | - // ... |
|
88 | + // Descriptions of general fields (alphabetized) |
|
89 | + // ... |
|
90 | 90 | |
91 | - return $data; |
|
91 | + return $data; |
|
92 | 92 | } |
@@ -7,15 +7,15 @@ |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | class views_handler_argument_boincuser_id extends views_handler_argument_numeric { |
10 | - function construct() { |
|
10 | + function construct() { |
|
11 | 11 | parent::construct(); |
12 | - } |
|
12 | + } |
|
13 | 13 | |
14 | - function set_argument($arg) { |
|
14 | + function set_argument($arg) { |
|
15 | 15 | // When setting the ID argument, convert to BOINC ID |
16 | 16 | $id = is_numeric($arg) ? $arg : 0; |
17 | 17 | $boinc_id = db_result(db_query("SELECT boinc_id FROM {boincuser} WHERE uid = %d", $id)); |
18 | 18 | $this->argument = $boinc_id; |
19 | 19 | return $this->validate_arg($boinc_id); |
20 | - } |
|
20 | + } |
|
21 | 21 | } |
@@ -6,15 +6,15 @@ |
||
6 | 6 | */ |
7 | 7 | |
8 | 8 | class views_handler_field_boincwork_host_app_et_avg extends views_handler_field { |
9 | - function construct() { |
|
9 | + function construct() { |
|
10 | 10 | parent::construct(); |
11 | - } |
|
11 | + } |
|
12 | 12 | |
13 | - function render($values) { |
|
13 | + function render($values) { |
|
14 | 14 | $gflops = 0; |
15 | 15 | if ($values->host_app_version_et_avg) { |
16 | - $gflops = 1e-9 / $values->host_app_version_et_avg; |
|
16 | + $gflops = 1e-9 / $values->host_app_version_et_avg; |
|
17 | 17 | } |
18 | 18 | return round($gflops, 2) . ' GFLOPS'; |
19 | - } |
|
19 | + } |
|
20 | 20 | } |
@@ -6,12 +6,12 @@ |
||
6 | 6 | */ |
7 | 7 | |
8 | 8 | class views_handler_field_boincwork_host_app_turnaround_avg extends views_handler_field { |
9 | - function construct() { |
|
9 | + function construct() { |
|
10 | 10 | parent::construct(); |
11 | - } |
|
11 | + } |
|
12 | 12 | |
13 | - function render($values) { |
|
13 | + function render($values) { |
|
14 | 14 | $time_in_days = $values->host_app_version_turnaround_avg / (24*60*60); |
15 | 15 | return round($time_in_days, 2) . ' ' . t('days'); |
16 | - } |
|
16 | + } |
|
17 | 17 | } |
@@ -6,11 +6,11 @@ |
||
6 | 6 | */ |
7 | 7 | |
8 | 8 | class views_handler_field_boincwork_app_version_number extends views_handler_field { |
9 | - function construct() { |
|
9 | + function construct() { |
|
10 | 10 | parent::construct(); |
11 | - } |
|
11 | + } |
|
12 | 12 | |
13 | - function render($values) { |
|
13 | + function render($values) { |
|
14 | 14 | return sprintf("%01.2f", $values->app_version_host_app_version_version_num / 100); |
15 | - } |
|
15 | + } |
|
16 | 16 | } |
@@ -220,8 +220,7 @@ discard block |
||
220 | 220 | if (!$values['boinc_translate_transifex_pass']) { |
221 | 221 | if (!variable_get('boinc_translate_transifex_pass', '')) { |
222 | 222 | form_set_error('boinc_translate_transifex_pass', t('Password is required.')); |
223 | - } |
|
224 | - else { |
|
223 | + } else { |
|
225 | 224 | unset($form_state['values']['boinc_translate_transifex_pass']); |
226 | 225 | } |
227 | 226 | } |
@@ -260,8 +259,7 @@ discard block |
||
260 | 259 | 'boinc_translate_transifex_pass', |
261 | 260 | t('Transifex authentication failed.') |
262 | 261 | ); |
263 | - } |
|
264 | - else { |
|
262 | + } else { |
|
265 | 263 | $authenticated = TRUE; |
266 | 264 | } |
267 | 265 | } |
@@ -278,14 +276,12 @@ discard block |
||
278 | 276 | ); |
279 | 277 | if ($project_name AND $project_resources) { |
280 | 278 | $transifex_resources[$project_name] = $project_resources; |
281 | - } |
|
282 | - elseif ($project_name AND !$project_resources) { |
|
279 | + } elseif ($project_name AND !$project_resources) { |
|
283 | 280 | drupal_set_message( |
284 | 281 | t('No project-specific resources were provided'), |
285 | 282 | 'warning' |
286 | 283 | ); |
287 | - } |
|
288 | - elseif ($project_resources AND !$project_name) { |
|
284 | + } elseif ($project_resources AND !$project_name) { |
|
289 | 285 | drupal_set_message( |
290 | 286 | t('No project-specific Transifex project name was provided'), |
291 | 287 | 'warning' |
@@ -7,85 +7,85 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | /** |
10 | - * The BOINC translation settings form allows configuration of BTS integration |
|
11 | - * (and other translation related settings) |
|
12 | - */ |
|
10 | + * The BOINC translation settings form allows configuration of BTS integration |
|
11 | + * (and other translation related settings) |
|
12 | + */ |
|
13 | 13 | function boinctranslate_admin_settings(&$form_state) { |
14 | - $form = array(); |
|
15 | - $initialized = FALSE; |
|
16 | - $import_enabled = FALSE; |
|
17 | - $default = array( |
|
14 | + $form = array(); |
|
15 | + $initialized = FALSE; |
|
16 | + $import_enabled = FALSE; |
|
17 | + $default = array( |
|
18 | 18 | 'transifex_user' => variable_get('boinc_translate_transifex_user', ''), |
19 | 19 | 'transifex_pass' => variable_get('boinc_translate_transifex_pass', ''), |
20 | 20 | 'transifex_boinc_name' => variable_get( |
21 | - 'boinc_translate_transifex_standard_name', 'boinc' |
|
21 | + 'boinc_translate_transifex_standard_name', 'boinc' |
|
22 | 22 | ), |
23 | 23 | 'transifex_boinc_resources' => variable_get( |
24 | - 'boinc_translate_transifex_standard_resources', |
|
25 | - "project-generic\nweb" |
|
24 | + 'boinc_translate_transifex_standard_resources', |
|
25 | + "project-generic\nweb" |
|
26 | 26 | ), |
27 | 27 | 'transifex_boinc_drupal_resource' => variable_get( |
28 | - 'boinc_translate_transifex_boinc_drupal_resource', |
|
29 | - 'drupal' |
|
28 | + 'boinc_translate_transifex_boinc_drupal_resource', |
|
29 | + 'drupal' |
|
30 | 30 | ), |
31 | 31 | 'transifex_project_name' => variable_get( |
32 | - 'boinc_translate_transifex_project_name', '' |
|
32 | + 'boinc_translate_transifex_project_name', '' |
|
33 | 33 | ), |
34 | 34 | 'transifex_project_resources' => variable_get( |
35 | - 'boinc_translate_transifex_project_resources', '' |
|
35 | + 'boinc_translate_transifex_project_resources', '' |
|
36 | 36 | ), |
37 | - ); |
|
37 | + ); |
|
38 | 38 | |
39 | - if ($default['transifex_user'] AND $default['transifex_pass']) { |
|
39 | + if ($default['transifex_user'] AND $default['transifex_pass']) { |
|
40 | 40 | if (trim($default['transifex_boinc_resources']) |
41 | 41 | OR trim($default['transifex_project_resources'])) { |
42 | - $import_enabled = TRUE; |
|
42 | + $import_enabled = TRUE; |
|
43 | 43 | } |
44 | 44 | if ($default['transifex_boinc_name'] |
45 | 45 | AND $default['transifex_project_name'] |
46 | 46 | AND trim($default['transifex_boinc_resources']) |
47 | 47 | AND trim($default['transifex_project_resources'])) { |
48 | - $initialized = TRUE; |
|
48 | + $initialized = TRUE; |
|
49 | + } |
|
49 | 50 | } |
50 | - } |
|
51 | 51 | |
52 | - // Define the form |
|
52 | + // Define the form |
|
53 | 53 | |
54 | - $form['transifex'] = array( |
|
54 | + $form['transifex'] = array( |
|
55 | 55 | '#title' => t('Transifex settings'), |
56 | 56 | '#type' => 'fieldset', |
57 | 57 | '#description' => '', |
58 | 58 | '#collapsible' => TRUE, |
59 | 59 | '#collapsed' => $initialized, |
60 | 60 | '#attributes' => array('class' => '') |
61 | - ); |
|
62 | - $form['transifex']['boinc_translate_transifex_user'] = array( |
|
61 | + ); |
|
62 | + $form['transifex']['boinc_translate_transifex_user'] = array( |
|
63 | 63 | '#type' => 'textfield', |
64 | 64 | '#title' => t('User name'), |
65 | 65 | '#default_value' => $default['transifex_user'], |
66 | - ); |
|
67 | - $form['transifex']['boinc_translate_transifex_pass'] = array( |
|
66 | + ); |
|
67 | + $form['transifex']['boinc_translate_transifex_pass'] = array( |
|
68 | 68 | '#type' => 'password', |
69 | 69 | '#title' => t('Password'), |
70 | 70 | '#attributes' => array( |
71 | - 'placeholder' => $default['transifex_pass'] ? '********' : '', |
|
71 | + 'placeholder' => $default['transifex_pass'] ? '********' : '', |
|
72 | 72 | ), |
73 | - ); |
|
74 | - $form['transifex']['boinc_translate_transifex_standard_name'] = array( |
|
73 | + ); |
|
74 | + $form['transifex']['boinc_translate_transifex_standard_name'] = array( |
|
75 | 75 | '#type' => 'textfield', |
76 | 76 | '#title' => t('BOINC Transifex project'), |
77 | 77 | '#default_value' => $default['transifex_boinc_name'], |
78 | 78 | '#description' => t('The portion of the Transifex URL that identifies BOINC.'), |
79 | - ); |
|
80 | - $form['transifex']['boinc_translate_transifex_boinc_drupal_resource'] = array( |
|
79 | + ); |
|
80 | + $form['transifex']['boinc_translate_transifex_boinc_drupal_resource'] = array( |
|
81 | 81 | '#type' => 'textfield', |
82 | 82 | '#title' => t('Official BOINC Drupal Resource'), |
83 | 83 | '#default_value' => $default['transifex_boinc_drupal_resource'], |
84 | 84 | '#description' => t('The portion of the Transifex URL that identifies |
85 | 85 | the standard BOINC Resource to use for translation of the public |
86 | 86 | content defined in the Drupal system.'), |
87 | - ); |
|
88 | - $form['transifex']['boinc_translate_transifex_standard_resources'] = array( |
|
87 | + ); |
|
88 | + $form['transifex']['boinc_translate_transifex_standard_resources'] = array( |
|
89 | 89 | '#type' => 'textarea', |
90 | 90 | '#title' => t('Additional BOINC Resources'), |
91 | 91 | '#default_value' => $default['transifex_boinc_resources'], |
@@ -96,14 +96,14 @@ discard block |
||
96 | 96 | by any matching translations found in Resources further down the list. |
97 | 97 | Note that strings from the Official BOINC Drupal Resource will override |
98 | 98 | any strings from these additional Resources.'), |
99 | - ); |
|
100 | - $form['transifex']['boinc_translate_transifex_project_name'] = array( |
|
99 | + ); |
|
100 | + $form['transifex']['boinc_translate_transifex_project_name'] = array( |
|
101 | 101 | '#type' => 'textfield', |
102 | 102 | '#title' => t('Project-specific Transifex project'), |
103 | 103 | '#default_value' => $default['transifex_project_name'], |
104 | 104 | '#description' => t('The portion of the Transifex URL that identifies this project.'), |
105 | - ); |
|
106 | - $form['transifex']['boinc_translate_transifex_project_resources'] = array( |
|
105 | + ); |
|
106 | + $form['transifex']['boinc_translate_transifex_project_resources'] = array( |
|
107 | 107 | '#type' => 'textarea', |
108 | 108 | '#title' => t('Project-specific Resources'), |
109 | 109 | '#default_value' => $default['transifex_project_resources'], |
@@ -116,241 +116,241 @@ discard block |
||
116 | 116 | NOTE: The first Resource listed here is considered the primary Resource |
117 | 117 | for project-specific translations and will be updated by the "Update |
118 | 118 | project-specific Resources" button below!'), |
119 | - ); |
|
120 | - $form['transifex']['buttons']['submit'] = array( |
|
119 | + ); |
|
120 | + $form['transifex']['buttons']['submit'] = array( |
|
121 | 121 | '#type' => 'submit', |
122 | 122 | '#value' => t('Save configuration'), |
123 | - ); |
|
123 | + ); |
|
124 | 124 | |
125 | - $form['tools'] = array( |
|
125 | + $form['tools'] = array( |
|
126 | 126 | '#title' => t('Tools'), |
127 | 127 | '#type' => 'fieldset', |
128 | 128 | '#description' => '', |
129 | 129 | '#collapsible' => TRUE, |
130 | 130 | '#collapsed' => FALSE, |
131 | 131 | '#attributes' => array('class' => '') |
132 | - ); |
|
133 | - $form['tools']['initialize_languages_text'] = array( |
|
132 | + ); |
|
133 | + $form['tools']['initialize_languages_text'] = array( |
|
134 | 134 | '#type' => 'item', |
135 | 135 | '#title' => t('Install official BOINC languages'), |
136 | 136 | '#value' => t('Installs all languages from the BOINC Transifex project. Also installs missing languages in Drupal. <br>Languages must be enabled manually in Administer > Site configuration > Languages.'), |
137 | - ); |
|
138 | - $form['tools']['initialize_languages'] = array( |
|
137 | + ); |
|
138 | + $form['tools']['initialize_languages'] = array( |
|
139 | 139 | '#type' => 'button', |
140 | 140 | '#value' => t('Install official BOINC languages'), |
141 | 141 | '#executes_submit_callback' => TRUE, |
142 | 142 | '#submit' => array('boinctranslate_admin_settings_initialize_languages'), |
143 | 143 | '#disabled' => !$initialized, |
144 | - ); |
|
145 | - $form['tools']['import_now_text'] = array( |
|
144 | + ); |
|
145 | + $form['tools']['import_now_text'] = array( |
|
146 | 146 | '#type' => 'item', |
147 | 147 | '#title' => t('Import all translations'), |
148 | 148 | '#value' => t('Imports from Tranifex all configured Resources into their respective text groups.'), |
149 | - ); |
|
150 | - $form['tools']['import_now'] = array( |
|
149 | + ); |
|
150 | + $form['tools']['import_now'] = array( |
|
151 | 151 | '#type' => 'button', |
152 | 152 | '#value' => t('Import all translations'), |
153 | 153 | '#executes_submit_callback' => TRUE, |
154 | 154 | '#submit' => array('boinctranslate_admin_settings_import_now'), |
155 | 155 | '#disabled' => !$import_enabled, |
156 | - ); |
|
157 | - $form['tools']['download_boinc_pot_text'] = array( |
|
156 | + ); |
|
157 | + $form['tools']['download_boinc_pot_text'] = array( |
|
158 | 158 | '#type' => 'item', |
159 | 159 | '#title' => t('Download official BOINC-Drupal .pot'), |
160 | 160 | '#value' => t('Downloads the generic BOINC-Drupal .pot file. This is the template file for the boinc text group.'), |
161 | - ); |
|
162 | - $form['tools']['download_boinc_pot'] = array( |
|
161 | + ); |
|
162 | + $form['tools']['download_boinc_pot'] = array( |
|
163 | 163 | '#type' => 'button', |
164 | 164 | '#value' => t('Download official BOINC-Drupal .pot'), |
165 | 165 | '#executes_submit_callback' => TRUE, |
166 | 166 | '#submit' => array('boinctranslate_admin_settings_download_boinc_pot'), |
167 | 167 | '#disabled' => !$import_enabled, |
168 | - ); |
|
169 | - $form['tools']['download_project_pot_text'] = array( |
|
168 | + ); |
|
169 | + $form['tools']['download_project_pot_text'] = array( |
|
170 | 170 | '#type' => 'item', |
171 | 171 | '#title' => t('Download project-specific .pot'), |
172 | 172 | '#value' => t('Downloads the project-specific .pot file. This is the template file for the project text group.'), |
173 | - ); |
|
174 | - $form['tools']['download_project_pot'] = array( |
|
173 | + ); |
|
174 | + $form['tools']['download_project_pot'] = array( |
|
175 | 175 | '#type' => 'button', |
176 | 176 | '#value' => t('Download project-specific .pot'), |
177 | 177 | '#executes_submit_callback' => TRUE, |
178 | 178 | '#submit' => array('boinctranslate_admin_settings_download_project_pot'), |
179 | 179 | '#disabled' => !$import_enabled, |
180 | - ); |
|
181 | - if (user_access('update official BOINC translations')) { |
|
180 | + ); |
|
181 | + if (user_access('update official BOINC translations')) { |
|
182 | 182 | $form['tools']['update_official_boinc_text'] = array( |
183 | - '#type' => 'item', |
|
184 | - '#title' => t('Update official BOINC translations'), |
|
185 | - '#value' => t('Updates the official BOINC-Drupal Resource (translatable strings templates) to the BOINC Transifex project, based on the consolidated imported translations.<br><b>WARNING: Do not use unless you have write-access to the BOINC Transifex project.</b>'), |
|
183 | + '#type' => 'item', |
|
184 | + '#title' => t('Update official BOINC translations'), |
|
185 | + '#value' => t('Updates the official BOINC-Drupal Resource (translatable strings templates) to the BOINC Transifex project, based on the consolidated imported translations.<br><b>WARNING: Do not use unless you have write-access to the BOINC Transifex project.</b>'), |
|
186 | 186 | ); |
187 | 187 | $form['tools']['update_official_boinc'] = array( |
188 | - '#type' => 'button', |
|
189 | - '#value' => t('Update official BOINC translations'), |
|
190 | - '#executes_submit_callback' => TRUE, |
|
191 | - '#submit' => array('boinctranslate_admin_settings_update_official_boinc'), |
|
192 | - '#disabled' => !$import_enabled, |
|
188 | + '#type' => 'button', |
|
189 | + '#value' => t('Update official BOINC translations'), |
|
190 | + '#executes_submit_callback' => TRUE, |
|
191 | + '#submit' => array('boinctranslate_admin_settings_update_official_boinc'), |
|
192 | + '#disabled' => !$import_enabled, |
|
193 | 193 | ); |
194 | - } |
|
195 | - $form['tools']['export_now_text'] = array( |
|
194 | + } |
|
195 | + $form['tools']['export_now_text'] = array( |
|
196 | 196 | '#type' => 'item', |
197 | 197 | '#title' => t('Update project-specific Resources'), |
198 | 198 | '#value' => t('Updates the configured Resources (translatable strings templates) to the project\'s Transifex project.<br><b>WARNING: Do not use unless you have write-access to your project\'s Transifex project.</b>'), |
199 | - ); |
|
200 | - $form['tools']['export_now'] = array( |
|
199 | + ); |
|
200 | + $form['tools']['export_now'] = array( |
|
201 | 201 | '#type' => 'button', |
202 | 202 | '#value' => t('Update project-specific Resources'), |
203 | 203 | '#executes_submit_callback' => TRUE, |
204 | 204 | '#submit' => array('boinctranslate_admin_settings_export_now'), |
205 | 205 | '#disabled' => !$import_enabled, |
206 | - ); |
|
206 | + ); |
|
207 | 207 | |
208 | - $form['#submit'][] = 'system_settings_form_submit'; |
|
209 | - $form['#theme'] = 'system_settings_form'; |
|
208 | + $form['#submit'][] = 'system_settings_form_submit'; |
|
209 | + $form['#theme'] = 'system_settings_form'; |
|
210 | 210 | |
211 | - return $form; |
|
211 | + return $form; |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | function boinctranslate_admin_settings_export_now() { |
215 | - drupal_goto('admin/boinc/translation/export'); |
|
215 | + drupal_goto('admin/boinc/translation/export'); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | function boinctranslate_admin_settings_import_now() { |
219 | - drupal_goto('admin/boinc/translation/import'); |
|
219 | + drupal_goto('admin/boinc/translation/import'); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | function boinctranslate_admin_settings_initialize_languages() { |
223 | - drupal_goto('admin/boinc/translation/initialize-languages'); |
|
223 | + drupal_goto('admin/boinc/translation/initialize-languages'); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | function boinctranslate_admin_settings_update_official_boinc() { |
227 | - drupal_goto('admin/boinc/translation/update-official-boinc'); |
|
227 | + drupal_goto('admin/boinc/translation/update-official-boinc'); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | function boinctranslate_admin_settings_download_boinc_pot() { |
231 | - drupal_goto('admin/boinc/translation/download-pot/boinc'); |
|
231 | + drupal_goto('admin/boinc/translation/download-pot/boinc'); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | function boinctranslate_admin_settings_download_project_pot() { |
235 | - drupal_goto('admin/boinc/translation/download-pot/project'); |
|
235 | + drupal_goto('admin/boinc/translation/download-pot/project'); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | |
239 | 239 | /** |
240 | - * Validate the BOINC translation settings form. |
|
241 | - */ |
|
240 | + * Validate the BOINC translation settings form. |
|
241 | + */ |
|
242 | 242 | function boinctranslate_admin_settings_validate($form, &$form_state) { |
243 | - $values = $form_state['values']; |
|
244 | - $errors = array(); |
|
245 | - $api_base_url = 'https://www.transifex.com/api/2'; |
|
243 | + $values = $form_state['values']; |
|
244 | + $errors = array(); |
|
245 | + $api_base_url = 'https://www.transifex.com/api/2'; |
|
246 | 246 | |
247 | - if (!$values['boinc_translate_transifex_user']) { |
|
247 | + if (!$values['boinc_translate_transifex_user']) { |
|
248 | 248 | form_set_error('boinc_translate_transifex_user', t('User name is required.')); |
249 | - } |
|
250 | - if (!$values['boinc_translate_transifex_pass']) { |
|
249 | + } |
|
250 | + if (!$values['boinc_translate_transifex_pass']) { |
|
251 | 251 | if (!variable_get('boinc_translate_transifex_pass', '')) { |
252 | - form_set_error('boinc_translate_transifex_pass', t('Password is required.')); |
|
252 | + form_set_error('boinc_translate_transifex_pass', t('Password is required.')); |
|
253 | 253 | } |
254 | 254 | else { |
255 | - unset($form_state['values']['boinc_translate_transifex_pass']); |
|
255 | + unset($form_state['values']['boinc_translate_transifex_pass']); |
|
256 | + } |
|
256 | 257 | } |
257 | - } |
|
258 | - if (!$values['boinc_translate_transifex_standard_name']) { |
|
258 | + if (!$values['boinc_translate_transifex_standard_name']) { |
|
259 | 259 | form_set_error('boinc_translate_transifex_standard_name', |
260 | - t('BOINC Transifex project name is required.') |
|
260 | + t('BOINC Transifex project name is required.') |
|
261 | 261 | ); |
262 | - } |
|
263 | - if (!$values['boinc_translate_transifex_standard_resources']) { |
|
262 | + } |
|
263 | + if (!$values['boinc_translate_transifex_standard_resources']) { |
|
264 | 264 | form_set_error('boinc_translate_transifex_standard_resources', |
265 | - t('At least one BOINC Transifex project Resource is required.') |
|
265 | + t('At least one BOINC Transifex project Resource is required.') |
|
266 | 266 | ); |
267 | - } |
|
268 | - if (!$values['boinc_translate_transifex_project_resources']) { |
|
267 | + } |
|
268 | + if (!$values['boinc_translate_transifex_project_resources']) { |
|
269 | 269 | form_set_error('boinc_translate_transifex_project_resources', |
270 | - t('At least one project-specific Transifex Resource is required.') |
|
270 | + t('At least one project-specific Transifex Resource is required.') |
|
271 | 271 | ); |
272 | - } |
|
272 | + } |
|
273 | 273 | |
274 | - $username = $values['boinc_translate_transifex_user']; |
|
275 | - $password = ($values['boinc_translate_transifex_pass']) ? $values['boinc_translate_transifex_pass'] : variable_get('boinc_translate_transifex_pass', ''); |
|
276 | - $boinc_name = $values['boinc_translate_transifex_standard_name']; |
|
277 | - $boinc_resources = boinctranslate_parse_resources( |
|
274 | + $username = $values['boinc_translate_transifex_user']; |
|
275 | + $password = ($values['boinc_translate_transifex_pass']) ? $values['boinc_translate_transifex_pass'] : variable_get('boinc_translate_transifex_pass', ''); |
|
276 | + $boinc_name = $values['boinc_translate_transifex_standard_name']; |
|
277 | + $boinc_resources = boinctranslate_parse_resources( |
|
278 | 278 | $values['boinc_translate_transifex_standard_resources'] |
279 | - ); |
|
279 | + ); |
|
280 | 280 | |
281 | - if ($username AND $password AND $boinc_name AND $boinc_resources) { |
|
281 | + if ($username AND $password AND $boinc_name AND $boinc_resources) { |
|
282 | 282 | // Test authentication |
283 | 283 | $authenticated = FALSE; |
284 | 284 | $path = "project/{$boinc_name}/resource/{$boinc_resources[0]}/translation/en"; |
285 | 285 | $response = boinctranslate_transifex_request($path, NULL, TRUE, FALSE, $username, $password); |
286 | 286 | |
287 | 287 | if ($response) { |
288 | - if ($response == '401 UNAUTHORIZED') { |
|
288 | + if ($response == '401 UNAUTHORIZED') { |
|
289 | 289 | form_set_error( |
290 | - 'boinc_translate_transifex_pass', |
|
291 | - t('Transifex authentication failed.') |
|
290 | + 'boinc_translate_transifex_pass', |
|
291 | + t('Transifex authentication failed.') |
|
292 | 292 | ); |
293 | - } |
|
294 | - else { |
|
293 | + } |
|
294 | + else { |
|
295 | 295 | $authenticated = TRUE; |
296 | - } |
|
296 | + } |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | if ($authenticated) { |
300 | - // Prepare list of resources to validate |
|
301 | - $transifex_resources = array( |
|
300 | + // Prepare list of resources to validate |
|
301 | + $transifex_resources = array( |
|
302 | 302 | 'boinc' => $boinc_resources, |
303 | - ); |
|
304 | - // Parse project-specific resources |
|
305 | - $project_name = trim($values['boinc_translate_transifex_project_name']); |
|
306 | - $project_resources = boinctranslate_parse_resources( |
|
303 | + ); |
|
304 | + // Parse project-specific resources |
|
305 | + $project_name = trim($values['boinc_translate_transifex_project_name']); |
|
306 | + $project_resources = boinctranslate_parse_resources( |
|
307 | 307 | $values['boinc_translate_transifex_project_resources'] |
308 | - ); |
|
309 | - if ($project_name AND $project_resources) { |
|
308 | + ); |
|
309 | + if ($project_name AND $project_resources) { |
|
310 | 310 | $transifex_resources[$project_name] = $project_resources; |
311 | - } |
|
312 | - elseif ($project_name AND !$project_resources) { |
|
311 | + } |
|
312 | + elseif ($project_name AND !$project_resources) { |
|
313 | 313 | drupal_set_message( |
314 | - t('No project-specific resources were provided'), |
|
315 | - 'warning' |
|
314 | + t('No project-specific resources were provided'), |
|
315 | + 'warning' |
|
316 | 316 | ); |
317 | - } |
|
318 | - elseif ($project_resources AND !$project_name) { |
|
317 | + } |
|
318 | + elseif ($project_resources AND !$project_name) { |
|
319 | 319 | drupal_set_message( |
320 | - t('No project-specific Transifex project name was provided'), |
|
321 | - 'warning' |
|
320 | + t('No project-specific Transifex project name was provided'), |
|
321 | + 'warning' |
|
322 | 322 | ); |
323 | - } |
|
323 | + } |
|
324 | 324 | |
325 | - // Try to access the given resources |
|
326 | - foreach ($transifex_resources as $project => $resources) { |
|
325 | + // Try to access the given resources |
|
326 | + foreach ($transifex_resources as $project => $resources) { |
|
327 | 327 | foreach ($resources as $resource) { |
328 | 328 | |
329 | - $path = "project/{$project}/resource/{$resource}/translation/en"; |
|
330 | - $response = boinctranslate_transifex_request($path); |
|
329 | + $path = "project/{$project}/resource/{$resource}/translation/en"; |
|
330 | + $response = boinctranslate_transifex_request($path); |
|
331 | 331 | |
332 | - if ($response == '404 NOT FOUND') { |
|
332 | + if ($response == '404 NOT FOUND') { |
|
333 | 333 | form_set_error( |
334 | - 'boinc_translate_transifex_' . ($project == $boinc_name ? 'standard' : 'project') . '_resources', |
|
335 | - t('Resource %name not found in %project.', |
|
334 | + 'boinc_translate_transifex_' . ($project == $boinc_name ? 'standard' : 'project') . '_resources', |
|
335 | + t('Resource %name not found in %project.', |
|
336 | 336 | array( |
337 | - '%name' => $resource, |
|
338 | - '%project' => $project, |
|
337 | + '%name' => $resource, |
|
338 | + '%project' => $project, |
|
339 | + ) |
|
339 | 340 | ) |
340 | - ) |
|
341 | 341 | ); |
342 | - } |
|
342 | + } |
|
343 | 343 | } |
344 | - } |
|
344 | + } |
|
345 | + } |
|
345 | 346 | } |
346 | - } |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | /** |
350 | - * Handle post-validation submission of BOINC translation settings form. |
|
351 | - */ |
|
350 | + * Handle post-validation submission of BOINC translation settings form. |
|
351 | + */ |
|
352 | 352 | function boinctranslate_admin_settings_submit($form, &$form_state) { |
353 | - drupal_set_message(t('BOINC translation settings have been updated.')); |
|
353 | + drupal_set_message(t('BOINC translation settings have been updated.')); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 |