@@ -13,103 +13,103 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | function boincteam_views_data() { |
| 15 | 15 | |
| 16 | - // ----------------------------------------------------------------------------------------------- |
|
| 17 | - // Definition for team table |
|
| 18 | - // ----------------------------------------------------------------------------------------------- |
|
| 16 | + // ----------------------------------------------------------------------------------------------- |
|
| 17 | + // Definition for team table |
|
| 18 | + // ----------------------------------------------------------------------------------------------- |
|
| 19 | 19 | |
| 20 | - $data['team']['table']['group'] = t('BOINC'); |
|
| 20 | + $data['team']['table']['group'] = t('BOINC'); |
|
| 21 | 21 | |
| 22 | - $data['team']['table']['base'] = array( |
|
| 23 | - 'field' => 'id', |
|
| 24 | - 'title' => t('BOINC team'), |
|
| 25 | - 'help' => t('BOINC data for a team'), |
|
| 26 | - 'database' => 'boinc_rw' |
|
| 27 | - ); |
|
| 22 | + $data['team']['table']['base'] = array( |
|
| 23 | + 'field' => 'id', |
|
| 24 | + 'title' => t('BOINC team'), |
|
| 25 | + 'help' => t('BOINC data for a team'), |
|
| 26 | + 'database' => 'boinc_rw' |
|
| 27 | + ); |
|
| 28 | 28 | |
| 29 | - // This table references the {user} table. |
|
| 30 | - // This join creates an 'implicit' relationship to the user table, so that when |
|
| 31 | - // "User" is the base table, the fields are automatically available. |
|
| 29 | + // This table references the {user} table. |
|
| 30 | + // This join creates an 'implicit' relationship to the user table, so that when |
|
| 31 | + // "User" is the base table, the fields are automatically available. |
|
| 32 | 32 | |
| 33 | - // Index this array by the table name to which this table refers. |
|
| 34 | - // 'left_field' is the primary key in the referenced table. |
|
| 35 | - // 'field' is the foreign key in this table. |
|
| 33 | + // Index this array by the table name to which this table refers. |
|
| 34 | + // 'left_field' is the primary key in the referenced table. |
|
| 35 | + // 'field' is the foreign key in this table. |
|
| 36 | 36 | |
| 37 | - $data['team']['table']['join'] = array( |
|
| 37 | + $data['team']['table']['join'] = array( |
|
| 38 | 38 | 'user' => array( |
| 39 | - 'left_field' => 'id', |
|
| 40 | - 'field' => 'userid', |
|
| 39 | + 'left_field' => 'id', |
|
| 40 | + 'field' => 'userid', |
|
| 41 | 41 | ), |
| 42 | - ); |
|
| 42 | + ); |
|
| 43 | 43 | |
| 44 | - // Describe each of the individual fields in this table to Views. For |
|
| 45 | - // each field, you may define what field, sort, argument, and/or filter |
|
| 46 | - // handlers it supports. This will determine where in the Views interface you |
|
| 47 | - // may use the field. |
|
| 44 | + // Describe each of the individual fields in this table to Views. For |
|
| 45 | + // each field, you may define what field, sort, argument, and/or filter |
|
| 46 | + // handlers it supports. This will determine where in the Views interface you |
|
| 47 | + // may use the field. |
|
| 48 | 48 | |
| 49 | - // Primary keys allowed as arguments |
|
| 49 | + // Primary keys allowed as arguments |
|
| 50 | 50 | |
| 51 | - $data['team']['id'] = array( |
|
| 51 | + $data['team']['id'] = array( |
|
| 52 | 52 | 'title' => bts('Team ID', array(), NULL, 'boinc:team-id'), |
| 53 | 53 | 'help' => t('The BOINC ID of the team.'), |
| 54 | 54 | 'field' => array( |
| 55 | - 'handler' => 'views_handler_field_numeric', |
|
| 56 | - 'click sortable' => TRUE |
|
| 55 | + 'handler' => 'views_handler_field_numeric', |
|
| 56 | + 'click sortable' => TRUE |
|
| 57 | 57 | ), |
| 58 | 58 | 'argument' => array( |
| 59 | - 'handler' => 'views_handler_argument_boincteam_id', // custom handler |
|
| 60 | - 'name field' => 'title', // the field to display in the summary. |
|
| 61 | - 'numeric' => TRUE, |
|
| 62 | - 'validate type' => 'id' |
|
| 59 | + 'handler' => 'views_handler_argument_boincteam_id', // custom handler |
|
| 60 | + 'name field' => 'title', // the field to display in the summary. |
|
| 61 | + 'numeric' => TRUE, |
|
| 62 | + 'validate type' => 'id' |
|
| 63 | 63 | ), |
| 64 | 64 | 'relationship' => array( |
| 65 | - 'base' => 'team_delta', |
|
| 66 | - 'field' => 'id', |
|
| 67 | - 'base field' => 'teamid', |
|
| 68 | - 'handler' => 'views_handler_relationship', |
|
| 69 | - 'label' => t('Team History') |
|
| 65 | + 'base' => 'team_delta', |
|
| 66 | + 'field' => 'id', |
|
| 67 | + 'base field' => 'teamid', |
|
| 68 | + 'handler' => 'views_handler_relationship', |
|
| 69 | + 'label' => t('Team History') |
|
| 70 | 70 | ), |
| 71 | 71 | 'filter' => array( |
| 72 | - 'handler' => 'views_handler_filter_numeric' |
|
| 72 | + 'handler' => 'views_handler_filter_numeric' |
|
| 73 | 73 | ), |
| 74 | 74 | 'sort' => array( |
| 75 | - 'handler' => 'views_handler_sort_numeric' |
|
| 75 | + 'handler' => 'views_handler_sort_numeric' |
|
| 76 | 76 | ) |
| 77 | - ); |
|
| 77 | + ); |
|
| 78 | 78 | |
| 79 | - // Foreign key fields |
|
| 79 | + // Foreign key fields |
|
| 80 | 80 | |
| 81 | - $data['team']['userid'] = array( |
|
| 81 | + $data['team']['userid'] = array( |
|
| 82 | 82 | 'title' => bts('Founder', array(), NULL, 'boinc:view-team-info'), |
| 83 | 83 | 'help' => t('The founder of this team.'), |
| 84 | 84 | // This is a foreign key to the {user} table. When the view is configured |
| 85 | 85 | // with this relationship, all the fields for the related user node will be |
| 86 | 86 | // available. |
| 87 | 87 | 'argument' => array( |
| 88 | - 'handler' => 'views_handler_argument_boincuser_id', |
|
| 89 | - 'name field' => 'title', |
|
| 90 | - 'numeric' => TRUE, |
|
| 91 | - 'validate type' => 'id' |
|
| 88 | + 'handler' => 'views_handler_argument_boincuser_id', |
|
| 89 | + 'name field' => 'title', |
|
| 90 | + 'numeric' => TRUE, |
|
| 91 | + 'validate type' => 'id' |
|
| 92 | 92 | ), |
| 93 | 93 | 'relationship' => array( |
| 94 | - 'base' => 'user', |
|
| 95 | - 'field' => 'userid', |
|
| 96 | - 'handler' => 'views_handler_relationship', |
|
| 97 | - 'label' => t('User') |
|
| 94 | + 'base' => 'user', |
|
| 95 | + 'field' => 'userid', |
|
| 96 | + 'handler' => 'views_handler_relationship', |
|
| 97 | + 'label' => t('User') |
|
| 98 | 98 | ), |
| 99 | 99 | 'field' => array( |
| 100 | - 'handler' => 'views_handler_field_numeric', |
|
| 101 | - 'click sortable' => TRUE |
|
| 100 | + 'handler' => 'views_handler_field_numeric', |
|
| 101 | + 'click sortable' => TRUE |
|
| 102 | 102 | ), |
| 103 | 103 | 'filter' => array( |
| 104 | - 'handler' => 'views_handler_filter_numeric' |
|
| 104 | + 'handler' => 'views_handler_filter_numeric' |
|
| 105 | 105 | ), |
| 106 | 106 | 'sort' => array( |
| 107 | - 'handler' => 'views_handler_sort_numeric' |
|
| 107 | + 'handler' => 'views_handler_sort_numeric' |
|
| 108 | 108 | ) |
| 109 | - ); |
|
| 109 | + ); |
|
| 110 | 110 | |
| 111 | - // Descriptions of general fields (alphabetized) |
|
| 112 | - /* |
|
| 111 | + // Descriptions of general fields (alphabetized) |
|
| 112 | + /* |
|
| 113 | 113 | $data['team']['create_time'] = array( |
| 114 | 114 | 'title' => bts('Team established', array(), NULL, 'boinc:date-team-established'), |
| 115 | 115 | 'help' => t('When the BOINC team was created.'), |
@@ -140,298 +140,298 @@ discard block |
||
| 140 | 140 | ); |
| 141 | 141 | */ |
| 142 | 142 | |
| 143 | - $data['team']['country'] = array( |
|
| 143 | + $data['team']['country'] = array( |
|
| 144 | 144 | 'title' => bts('Country', array(), NULL, 'boinc:country-of-origin'), |
| 145 | 145 | 'help' => t('The country of a team.'), |
| 146 | 146 | 'field' => array( |
| 147 | - 'handler' => 'views_handler_field', |
|
| 148 | - 'click sortable' => TRUE |
|
| 147 | + 'handler' => 'views_handler_field', |
|
| 148 | + 'click sortable' => TRUE |
|
| 149 | 149 | ), |
| 150 | 150 | 'filter' => array( |
| 151 | - 'handler' => 'views_handler_filter_string' |
|
| 151 | + 'handler' => 'views_handler_filter_string' |
|
| 152 | 152 | ), |
| 153 | 153 | 'sort' => array( |
| 154 | - 'handler' => 'views_handler_sort_string' |
|
| 154 | + 'handler' => 'views_handler_sort_string' |
|
| 155 | 155 | ) |
| 156 | - ); |
|
| 157 | - $data['team']['expavg_credit'] = array( |
|
| 156 | + ); |
|
| 157 | + $data['team']['expavg_credit'] = array( |
|
| 158 | 158 | 'title' => bts('Recent average credit', array(), NULL, 'boinc:user-or-team-RAC'), |
| 159 | 159 | 'help' => t('A decaying average of team credit per day.'), |
| 160 | 160 | 'field' => array( |
| 161 | - 'handler' => 'views_handler_field_numeric', |
|
| 162 | - 'click sortable' => TRUE, |
|
| 163 | - 'float' => TRUE |
|
| 161 | + 'handler' => 'views_handler_field_numeric', |
|
| 162 | + 'click sortable' => TRUE, |
|
| 163 | + 'float' => TRUE |
|
| 164 | 164 | ), |
| 165 | 165 | 'filter' => array( |
| 166 | - 'handler' => 'views_handler_filter_numeric' |
|
| 166 | + 'handler' => 'views_handler_filter_numeric' |
|
| 167 | 167 | ), |
| 168 | 168 | 'sort' => array( |
| 169 | - 'handler' => 'views_handler_sort_numeric' |
|
| 169 | + 'handler' => 'views_handler_sort_numeric' |
|
| 170 | 170 | ) |
| 171 | - ); |
|
| 172 | - $data['team']['name'] = array( |
|
| 171 | + ); |
|
| 172 | + $data['team']['name'] = array( |
|
| 173 | 173 | 'title' => bts('Name', array(), NULL, 'boinc:user-or-team-name'), |
| 174 | 174 | 'help' => t('The name of the team.'), |
| 175 | 175 | 'field' => array( |
| 176 | - 'handler' => 'views_handler_field', |
|
| 177 | - 'click sortable' => TRUE |
|
| 176 | + 'handler' => 'views_handler_field', |
|
| 177 | + 'click sortable' => TRUE |
|
| 178 | 178 | ), |
| 179 | 179 | 'filter' => array( |
| 180 | - 'handler' => 'views_handler_filter_string' |
|
| 180 | + 'handler' => 'views_handler_filter_string' |
|
| 181 | 181 | ), |
| 182 | 182 | 'sort' => array( |
| 183 | - 'handler' => 'views_handler_sort_string' |
|
| 183 | + 'handler' => 'views_handler_sort_string' |
|
| 184 | 184 | ) |
| 185 | - ); |
|
| 186 | - $data['team']['nusers'] = array( |
|
| 185 | + ); |
|
| 186 | + $data['team']['nusers'] = array( |
|
| 187 | 187 | 'title' => bts('Members', array(), NULL, 'boinc:team-members'), |
| 188 | 188 | 'help' => t('Count of team members.'), |
| 189 | 189 | 'field' => array( |
| 190 | - 'handler' => 'views_handler_field_numeric', |
|
| 191 | - 'click sortable' => TRUE |
|
| 190 | + 'handler' => 'views_handler_field_numeric', |
|
| 191 | + 'click sortable' => TRUE |
|
| 192 | 192 | ), |
| 193 | 193 | 'filter' => array( |
| 194 | - 'handler' => 'views_handler_filter_numeric' |
|
| 194 | + 'handler' => 'views_handler_filter_numeric' |
|
| 195 | 195 | ), |
| 196 | 196 | 'sort' => array( |
| 197 | - 'handler' => 'views_handler_sort_numeric' |
|
| 197 | + 'handler' => 'views_handler_sort_numeric' |
|
| 198 | 198 | ) |
| 199 | - ); |
|
| 200 | - $data['team']['total_credit'] = array( |
|
| 199 | + ); |
|
| 200 | + $data['team']['total_credit'] = array( |
|
| 201 | 201 | 'title' => bts('Total credit', array(), NULL, 'boinc:user-or-team-total-credits'), |
| 202 | 202 | 'help' => t('The total team accumulated BOINC credit.'), |
| 203 | 203 | 'field' => array( |
| 204 | - 'handler' => 'views_handler_field_numeric', |
|
| 205 | - 'click sortable' => TRUE, |
|
| 206 | - 'float' => TRUE |
|
| 204 | + 'handler' => 'views_handler_field_numeric', |
|
| 205 | + 'click sortable' => TRUE, |
|
| 206 | + 'float' => TRUE |
|
| 207 | 207 | ), |
| 208 | 208 | 'filter' => array( |
| 209 | - 'handler' => 'views_handler_filter_numeric' |
|
| 209 | + 'handler' => 'views_handler_filter_numeric' |
|
| 210 | 210 | ), |
| 211 | 211 | 'sort' => array( |
| 212 | - 'handler' => 'views_handler_sort_numeric' |
|
| 212 | + 'handler' => 'views_handler_sort_numeric' |
|
| 213 | 213 | ) |
| 214 | - ); |
|
| 214 | + ); |
|
| 215 | 215 | |
| 216 | - // ----------------------------------------------------------------------------------------------- |
|
| 217 | - // Definition for team_admin table |
|
| 218 | - // ----------------------------------------------------------------------------------------------- |
|
| 216 | + // ----------------------------------------------------------------------------------------------- |
|
| 217 | + // Definition for team_admin table |
|
| 218 | + // ----------------------------------------------------------------------------------------------- |
|
| 219 | 219 | |
| 220 | - $data['team_admin']['table']['group'] = t('BOINC'); |
|
| 220 | + $data['team_admin']['table']['group'] = t('BOINC'); |
|
| 221 | 221 | |
| 222 | - $data['team_admin']['table']['base'] = array( |
|
| 223 | - 'field' => 'id', |
|
| 224 | - 'title' => t('BOINC team admins'), |
|
| 225 | - 'help' => t('BOINC admins for a team'), |
|
| 226 | - 'database' => 'boinc_rw' |
|
| 227 | - ); |
|
| 222 | + $data['team_admin']['table']['base'] = array( |
|
| 223 | + 'field' => 'id', |
|
| 224 | + 'title' => t('BOINC team admins'), |
|
| 225 | + 'help' => t('BOINC admins for a team'), |
|
| 226 | + 'database' => 'boinc_rw' |
|
| 227 | + ); |
|
| 228 | 228 | |
| 229 | - // This table references the {team} table. |
|
| 230 | - // This join creates an 'implicit' relationship to the team table, so that when |
|
| 231 | - // "Team" is the base table, the fields are automatically available. |
|
| 229 | + // This table references the {team} table. |
|
| 230 | + // This join creates an 'implicit' relationship to the team table, so that when |
|
| 231 | + // "Team" is the base table, the fields are automatically available. |
|
| 232 | 232 | |
| 233 | - // Index this array by the table name to which this table refers. |
|
| 234 | - // 'left_field' is the primary key in the referenced table. |
|
| 235 | - // 'field' is the foreign key in this table. |
|
| 233 | + // Index this array by the table name to which this table refers. |
|
| 234 | + // 'left_field' is the primary key in the referenced table. |
|
| 235 | + // 'field' is the foreign key in this table. |
|
| 236 | 236 | |
| 237 | - $data['team_admin']['table']['join'] = array( |
|
| 237 | + $data['team_admin']['table']['join'] = array( |
|
| 238 | 238 | 'team' => array( |
| 239 | - 'left_field' => 'id', |
|
| 240 | - 'field' => 'teamid', |
|
| 239 | + 'left_field' => 'id', |
|
| 240 | + 'field' => 'teamid', |
|
| 241 | 241 | ), |
| 242 | - ); |
|
| 242 | + ); |
|
| 243 | 243 | |
| 244 | - // Describe each of the individual fields in this table to Views. For |
|
| 245 | - // each field, you may define what field, sort, argument, and/or filter |
|
| 246 | - // handlers it supports. This will determine where in the Views interface you |
|
| 247 | - // may use the field. |
|
| 244 | + // Describe each of the individual fields in this table to Views. For |
|
| 245 | + // each field, you may define what field, sort, argument, and/or filter |
|
| 246 | + // handlers it supports. This will determine where in the Views interface you |
|
| 247 | + // may use the field. |
|
| 248 | 248 | |
| 249 | - // Primary keys allowed as arguments |
|
| 249 | + // Primary keys allowed as arguments |
|
| 250 | 250 | |
| 251 | - $data['team_admin']['teamid'] = array( |
|
| 251 | + $data['team_admin']['teamid'] = array( |
|
| 252 | 252 | 'title' => bts('Team ID', array(), NULL, 'boinc:team-id'), |
| 253 | 253 | 'help' => t('The BOINC ID of the team on which this user is an admin.'), |
| 254 | 254 | 'field' => array( |
| 255 | - 'handler' => 'views_handler_field_numeric', |
|
| 256 | - 'click sortable' => TRUE |
|
| 255 | + 'handler' => 'views_handler_field_numeric', |
|
| 256 | + 'click sortable' => TRUE |
|
| 257 | 257 | ), |
| 258 | 258 | 'argument' => array( |
| 259 | - 'handler' => 'views_handler_argument_boincteam_id', // custom handler |
|
| 260 | - 'name field' => 'title', // the field to display in the summary. |
|
| 261 | - 'numeric' => TRUE, |
|
| 262 | - 'validate type' => 'id' |
|
| 259 | + 'handler' => 'views_handler_argument_boincteam_id', // custom handler |
|
| 260 | + 'name field' => 'title', // the field to display in the summary. |
|
| 261 | + 'numeric' => TRUE, |
|
| 262 | + 'validate type' => 'id' |
|
| 263 | 263 | ), |
| 264 | 264 | 'relationship' => array( |
| 265 | - 'base' => 'team', |
|
| 266 | - 'field' => 'teamid', |
|
| 267 | - 'handler' => 'views_handler_relationship', |
|
| 268 | - 'label' => t('Team') |
|
| 265 | + 'base' => 'team', |
|
| 266 | + 'field' => 'teamid', |
|
| 267 | + 'handler' => 'views_handler_relationship', |
|
| 268 | + 'label' => t('Team') |
|
| 269 | 269 | ), |
| 270 | 270 | 'filter' => array( |
| 271 | - 'handler' => 'views_handler_filter_numeric' |
|
| 271 | + 'handler' => 'views_handler_filter_numeric' |
|
| 272 | 272 | ), |
| 273 | 273 | 'sort' => array( |
| 274 | - 'handler' => 'views_handler_sort_numeric' |
|
| 274 | + 'handler' => 'views_handler_sort_numeric' |
|
| 275 | 275 | ) |
| 276 | - ); |
|
| 276 | + ); |
|
| 277 | 277 | |
| 278 | - // Foreign key fields |
|
| 278 | + // Foreign key fields |
|
| 279 | 279 | |
| 280 | - $data['team_admin']['userid'] = array( |
|
| 280 | + $data['team_admin']['userid'] = array( |
|
| 281 | 281 | 'title' => bts('User ID', array(), NULL, 'boinc:user-details'), |
| 282 | 282 | 'help' => t('The user that is a team admin.'), |
| 283 | 283 | // This is a foreign key to the {user} table. When the view is configured |
| 284 | 284 | // with this relationship, all the fields for the related user node will be |
| 285 | 285 | // available. |
| 286 | 286 | 'argument' => array( |
| 287 | - 'handler' => 'views_handler_argument_boincteam_id', |
|
| 288 | - 'name field' => 'title', |
|
| 289 | - 'numeric' => TRUE, |
|
| 290 | - 'validate type' => 'id' |
|
| 287 | + 'handler' => 'views_handler_argument_boincteam_id', |
|
| 288 | + 'name field' => 'title', |
|
| 289 | + 'numeric' => TRUE, |
|
| 290 | + 'validate type' => 'id' |
|
| 291 | 291 | ), |
| 292 | 292 | 'relationship' => array( |
| 293 | - 'base' => 'user', |
|
| 294 | - 'field' => 'userid', |
|
| 295 | - 'handler' => 'views_handler_relationship', |
|
| 296 | - 'label' => bts('User', array(), NULL, 'boinc:user-on-team') |
|
| 293 | + 'base' => 'user', |
|
| 294 | + 'field' => 'userid', |
|
| 295 | + 'handler' => 'views_handler_relationship', |
|
| 296 | + 'label' => bts('User', array(), NULL, 'boinc:user-on-team') |
|
| 297 | 297 | ), |
| 298 | 298 | 'field' => array( |
| 299 | - 'handler' => 'views_handler_field_numeric', |
|
| 300 | - 'click sortable' => TRUE |
|
| 299 | + 'handler' => 'views_handler_field_numeric', |
|
| 300 | + 'click sortable' => TRUE |
|
| 301 | 301 | ), |
| 302 | 302 | 'filter' => array( |
| 303 | - 'handler' => 'views_handler_filter_numeric' |
|
| 303 | + 'handler' => 'views_handler_filter_numeric' |
|
| 304 | 304 | ), |
| 305 | 305 | 'sort' => array( |
| 306 | - 'handler' => 'views_handler_sort_numeric' |
|
| 306 | + 'handler' => 'views_handler_sort_numeric' |
|
| 307 | 307 | ) |
| 308 | - ); |
|
| 308 | + ); |
|
| 309 | 309 | |
| 310 | - // Descriptions of general fields (alphabetized) |
|
| 310 | + // Descriptions of general fields (alphabetized) |
|
| 311 | 311 | |
| 312 | - $data['team_admin']['create_time'] = array( |
|
| 312 | + $data['team_admin']['create_time'] = array( |
|
| 313 | 313 | 'title' => bts('Admin since', array(), NULL, 'boinc:team-when-user-became-an-admin'), |
| 314 | 314 | 'help' => t('When the BOINC user became a team admin.'), |
| 315 | 315 | 'field' => array( |
| 316 | - 'handler' => 'views_handler_field_date', |
|
| 317 | - 'click sortable' => TRUE |
|
| 316 | + 'handler' => 'views_handler_field_date', |
|
| 317 | + 'click sortable' => TRUE |
|
| 318 | 318 | ), |
| 319 | 319 | 'filter' => array( |
| 320 | - 'handler' => 'views_handler_filter_date' |
|
| 320 | + 'handler' => 'views_handler_filter_date' |
|
| 321 | 321 | ), |
| 322 | 322 | 'sort' => array( |
| 323 | - 'handler' => 'views_handler_sort_date' |
|
| 323 | + 'handler' => 'views_handler_sort_date' |
|
| 324 | 324 | ) |
| 325 | - ); |
|
| 325 | + ); |
|
| 326 | 326 | |
| 327 | - // ----------------------------------------------------------------------------------------------- |
|
| 328 | - // Definition for team_delta table |
|
| 329 | - // ----------------------------------------------------------------------------------------------- |
|
| 327 | + // ----------------------------------------------------------------------------------------------- |
|
| 328 | + // Definition for team_delta table |
|
| 329 | + // ----------------------------------------------------------------------------------------------- |
|
| 330 | 330 | |
| 331 | - $data['team_delta']['table']['group'] = t('BOINC'); |
|
| 331 | + $data['team_delta']['table']['group'] = t('BOINC'); |
|
| 332 | 332 | |
| 333 | - // Describe each of the individual fields in this table to Views. For |
|
| 334 | - // each field, you may define what field, sort, argument, and/or filter |
|
| 335 | - // handlers it supports. This will determine where in the Views interface you |
|
| 336 | - // may use the field. |
|
| 333 | + // Describe each of the individual fields in this table to Views. For |
|
| 334 | + // each field, you may define what field, sort, argument, and/or filter |
|
| 335 | + // handlers it supports. This will determine where in the Views interface you |
|
| 336 | + // may use the field. |
|
| 337 | 337 | |
| 338 | - // Primary keys allowed as arguments |
|
| 338 | + // Primary keys allowed as arguments |
|
| 339 | 339 | |
| 340 | - $data['team_delta']['teamid'] = array( |
|
| 340 | + $data['team_delta']['teamid'] = array( |
|
| 341 | 341 | 'title' => bts('Team ID', array(), NULL, 'boinc:team-id'), |
| 342 | 342 | 'help' => t('The team ID for this team history event.'), |
| 343 | 343 | // This is a foreign key to the {team} table. When the view is configured |
| 344 | 344 | // with this relationship, all the fields for the related user node will be |
| 345 | 345 | // available. |
| 346 | 346 | 'argument' => array( |
| 347 | - 'handler' => 'views_handler_argument_boincteam_id', |
|
| 348 | - 'name field' => 'title', |
|
| 349 | - 'numeric' => TRUE, |
|
| 350 | - 'validate type' => 'id' |
|
| 347 | + 'handler' => 'views_handler_argument_boincteam_id', |
|
| 348 | + 'name field' => 'title', |
|
| 349 | + 'numeric' => TRUE, |
|
| 350 | + 'validate type' => 'id' |
|
| 351 | 351 | ), |
| 352 | 352 | 'field' => array( |
| 353 | - 'handler' => 'views_handler_field_numeric', |
|
| 354 | - 'click sortable' => TRUE |
|
| 353 | + 'handler' => 'views_handler_field_numeric', |
|
| 354 | + 'click sortable' => TRUE |
|
| 355 | 355 | ), |
| 356 | 356 | 'filter' => array( |
| 357 | - 'handler' => 'views_handler_filter_numeric' |
|
| 357 | + 'handler' => 'views_handler_filter_numeric' |
|
| 358 | 358 | ), |
| 359 | 359 | 'sort' => array( |
| 360 | - 'handler' => 'views_handler_sort_numeric' |
|
| 360 | + 'handler' => 'views_handler_sort_numeric' |
|
| 361 | 361 | ) |
| 362 | - ); |
|
| 362 | + ); |
|
| 363 | 363 | |
| 364 | - // Foreign key fields |
|
| 364 | + // Foreign key fields |
|
| 365 | 365 | |
| 366 | - $data['team_delta']['userid'] = array( |
|
| 366 | + $data['team_delta']['userid'] = array( |
|
| 367 | 367 | 'title' => bts('User ID', array(), NULL, 'boinc:user-details'), |
| 368 | 368 | 'help' => t('The user for this team history event.'), |
| 369 | 369 | 'relationship' => array( |
| 370 | - 'base' => 'user', |
|
| 371 | - 'field' => 'userid', |
|
| 372 | - 'handler' => 'views_handler_relationship', |
|
| 373 | - 'label' => t('User') |
|
| 370 | + 'base' => 'user', |
|
| 371 | + 'field' => 'userid', |
|
| 372 | + 'handler' => 'views_handler_relationship', |
|
| 373 | + 'label' => t('User') |
|
| 374 | 374 | ), |
| 375 | 375 | 'field' => array( |
| 376 | - 'handler' => 'views_handler_field_numeric', |
|
| 377 | - 'click sortable' => TRUE |
|
| 376 | + 'handler' => 'views_handler_field_numeric', |
|
| 377 | + 'click sortable' => TRUE |
|
| 378 | 378 | ), |
| 379 | 379 | 'filter' => array( |
| 380 | - 'handler' => 'views_handler_filter_numeric' |
|
| 380 | + 'handler' => 'views_handler_filter_numeric' |
|
| 381 | 381 | ), |
| 382 | 382 | 'sort' => array( |
| 383 | - 'handler' => 'views_handler_sort_numeric' |
|
| 383 | + 'handler' => 'views_handler_sort_numeric' |
|
| 384 | 384 | ) |
| 385 | - ); |
|
| 385 | + ); |
|
| 386 | 386 | |
| 387 | - // Descriptions of general fields (alphabetized) |
|
| 387 | + // Descriptions of general fields (alphabetized) |
|
| 388 | 388 | |
| 389 | - $data['team_delta']['joining'] = array( |
|
| 389 | + $data['team_delta']['joining'] = array( |
|
| 390 | 390 | 'title' => bts('User joined', array(), NULL, 'boinc:user-joined-or-leaving-team'), |
| 391 | 391 | 'help' => t('Whether the event is the user joining the team or leaving.'), |
| 392 | 392 | 'field' => array( |
| 393 | - 'handler' => 'views_handler_field_numeric', |
|
| 394 | - 'click sortable' => TRUE |
|
| 393 | + 'handler' => 'views_handler_field_numeric', |
|
| 394 | + 'click sortable' => TRUE |
|
| 395 | 395 | ), |
| 396 | 396 | 'filter' => array( |
| 397 | - 'handler' => 'views_handler_filter_numeric' |
|
| 397 | + 'handler' => 'views_handler_filter_numeric' |
|
| 398 | 398 | ), |
| 399 | 399 | 'sort' => array( |
| 400 | - 'handler' => 'views_handler_sort_numeric' |
|
| 400 | + 'handler' => 'views_handler_sort_numeric' |
|
| 401 | 401 | ) |
| 402 | - ); |
|
| 403 | - $data['team_delta']['timestamp'] = array( |
|
| 402 | + ); |
|
| 403 | + $data['team_delta']['timestamp'] = array( |
|
| 404 | 404 | 'title' => bts('Timestamp', array(), NULL, 'boinc:team-history-timestamp'), |
| 405 | 405 | 'help' => t('When the BOINC team history event took place.'), |
| 406 | 406 | 'field' => array( |
| 407 | - 'handler' => 'views_handler_field_date', |
|
| 408 | - 'click sortable' => TRUE |
|
| 407 | + 'handler' => 'views_handler_field_date', |
|
| 408 | + 'click sortable' => TRUE |
|
| 409 | 409 | ), |
| 410 | 410 | 'filter' => array( |
| 411 | - 'handler' => 'views_handler_filter_date' |
|
| 411 | + 'handler' => 'views_handler_filter_date' |
|
| 412 | 412 | ), |
| 413 | 413 | 'sort' => array( |
| 414 | - 'handler' => 'views_handler_sort_date' |
|
| 414 | + 'handler' => 'views_handler_sort_date' |
|
| 415 | 415 | ) |
| 416 | - ); |
|
| 417 | - $data['team_delta']['total_credit'] = array( |
|
| 416 | + ); |
|
| 417 | + $data['team_delta']['total_credit'] = array( |
|
| 418 | 418 | 'title' => bts('Total credit', array(), NULL, 'user-or-team-total-credits'), |
| 419 | 419 | 'help' => t('The total accumulated BOINC credit of the user when the |
| 420 | 420 | history event took place.'), |
| 421 | 421 | 'field' => array( |
| 422 | - 'handler' => 'views_handler_field_numeric', |
|
| 423 | - 'click sortable' => TRUE, |
|
| 424 | - 'float' => TRUE |
|
| 422 | + 'handler' => 'views_handler_field_numeric', |
|
| 423 | + 'click sortable' => TRUE, |
|
| 424 | + 'float' => TRUE |
|
| 425 | 425 | ), |
| 426 | 426 | 'filter' => array( |
| 427 | - 'handler' => 'views_handler_filter_numeric' |
|
| 427 | + 'handler' => 'views_handler_filter_numeric' |
|
| 428 | 428 | ), |
| 429 | 429 | 'sort' => array( |
| 430 | - 'handler' => 'views_handler_sort_numeric' |
|
| 430 | + 'handler' => 'views_handler_sort_numeric' |
|
| 431 | 431 | ) |
| 432 | - ); |
|
| 432 | + ); |
|
| 433 | 433 | |
| 434 | - return $data; |
|
| 434 | + return $data; |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | /* |
@@ -442,14 +442,14 @@ discard block |
||
| 442 | 442 | */ |
| 443 | 443 | |
| 444 | 444 | function boincteam_views_handlers() { |
| 445 | - return array( |
|
| 445 | + return array( |
|
| 446 | 446 | 'info' => array( |
| 447 | - 'path' => drupal_get_path('module', 'boincteam') . '/views', |
|
| 447 | + 'path' => drupal_get_path('module', 'boincteam') . '/views', |
|
| 448 | 448 | ), |
| 449 | 449 | 'handlers' => array( |
| 450 | - 'views_handler_argument_boincteam_id' => array( |
|
| 450 | + 'views_handler_argument_boincteam_id' => array( |
|
| 451 | 451 | 'parent' => 'views_handler_argument_numeric' |
| 452 | - ) |
|
| 452 | + ) |
|
| 453 | 453 | ) |
| 454 | - ); |
|
| 454 | + ); |
|
| 455 | 455 | } |
@@ -25,29 +25,29 @@ discard block |
||
| 25 | 25 | * Implementation of hook_menu() |
| 26 | 26 | */ |
| 27 | 27 | function boincteam_forum_menu() { |
| 28 | - $items = array(); |
|
| 28 | + $items = array(); |
|
| 29 | 29 | |
| 30 | - return $items; |
|
| 30 | + return $items; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * Implementation of hook_form_alter() |
| 35 | 35 | */ |
| 36 | 36 | function boincteam_forum_form_alter(&$form, $form_state, $form_id) { |
| 37 | - switch ($form_id) { |
|
| 38 | - // Team forum node edit form |
|
| 39 | - case 'team_forum_node_form': |
|
| 37 | + switch ($form_id) { |
|
| 38 | + // Team forum node edit form |
|
| 39 | + case 'team_forum_node_form': |
|
| 40 | 40 | |
| 41 | 41 | // Internal fields to indicate where these changes are taking place |
| 42 | 42 | array_unshift($form, array( |
| 43 | - 'tfid' => array( |
|
| 43 | + 'tfid' => array( |
|
| 44 | 44 | '#type' => 'hidden', |
| 45 | 45 | '#value' => arg(3), |
| 46 | - ), |
|
| 46 | + ), |
|
| 47 | 47 | )); |
| 48 | 48 | break; |
| 49 | 49 | |
| 50 | - default: |
|
| 50 | + default: |
|
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | |
@@ -56,26 +56,26 @@ discard block |
||
| 56 | 56 | * Obsolete in Drupal 7... |
| 57 | 57 | */ |
| 58 | 58 | function boincteam_forum_nodeapi(&$node, $op, $a3 = null, $a4 = null) { |
| 59 | - // In Drupal 7, these operation cases will all exist as their own hooks, |
|
| 60 | - // so let's approximate that here so that this function can simply be removed |
|
| 61 | - // upon migration to 7 |
|
| 62 | - switch($op) { |
|
| 63 | - case 'insert': |
|
| 59 | + // In Drupal 7, these operation cases will all exist as their own hooks, |
|
| 60 | + // so let's approximate that here so that this function can simply be removed |
|
| 61 | + // upon migration to 7 |
|
| 62 | + switch($op) { |
|
| 63 | + case 'insert': |
|
| 64 | 64 | boincteam_forum_node_insert($node); |
| 65 | 65 | break; |
| 66 | - case 'load': |
|
| 66 | + case 'load': |
|
| 67 | 67 | boincteam_forum_node_load($node); |
| 68 | 68 | break; |
| 69 | - case 'update': |
|
| 69 | + case 'update': |
|
| 70 | 70 | boincteam_forum_node_update($node); |
| 71 | 71 | break; |
| 72 | - case 'validate': |
|
| 72 | + case 'validate': |
|
| 73 | 73 | boincteam_forum_node_validate($node); |
| 74 | 74 | break; |
| 75 | - case 'view': |
|
| 75 | + case 'view': |
|
| 76 | 76 | boincteam_forum_node_view($node); |
| 77 | 77 | break; |
| 78 | - default: |
|
| 78 | + default: |
|
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | |
@@ -84,21 +84,21 @@ discard block |
||
| 84 | 84 | * is inserted (forward compatible to Drupal 7) |
| 85 | 85 | */ |
| 86 | 86 | function boincteam_forum_node_insert($node) { |
| 87 | - switch($node->type) { |
|
| 88 | - case 'team_forum': |
|
| 87 | + switch($node->type) { |
|
| 88 | + case 'team_forum': |
|
| 89 | 89 | $account = user_load($node->uid); |
| 90 | 90 | $team_id = boincteam_forum_lookup_nid($node->tfid); |
| 91 | 91 | if ($account->team == $team_id) { |
| 92 | - db_query(" |
|
| 92 | + db_query(" |
|
| 93 | 93 | INSERT INTO {boincteam_forum_node} SET |
| 94 | 94 | nid = %d, |
| 95 | 95 | tfid = %d", |
| 96 | 96 | $node->nid, $node->tfid |
| 97 | - ); |
|
| 97 | + ); |
|
| 98 | 98 | } |
| 99 | 99 | unset($node->tfid); |
| 100 | 100 | break; |
| 101 | - default: |
|
| 101 | + default: |
|
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | |
@@ -107,15 +107,15 @@ discard block |
||
| 107 | 107 | * is loaded (forward compatible to Drupal 7) |
| 108 | 108 | */ |
| 109 | 109 | function boincteam_forum_node_load($node) { |
| 110 | - switch($node->type) { |
|
| 111 | - case 'team_forum': |
|
| 110 | + switch($node->type) { |
|
| 111 | + case 'team_forum': |
|
| 112 | 112 | $node->tfid = db_result(db_query(" |
| 113 | 113 | SELECT tfid FROM {boincteam_forum_node} |
| 114 | 114 | WHERE nid = %d", $node->nid |
| 115 | 115 | )); |
| 116 | 116 | break; |
| 117 | 117 | |
| 118 | - default: |
|
| 118 | + default: |
|
| 119 | 119 | |
| 120 | 120 | } |
| 121 | 121 | } |
@@ -125,12 +125,12 @@ discard block |
||
| 125 | 125 | * is updated (forward compatible to Drupal 7) |
| 126 | 126 | */ |
| 127 | 127 | function boincteam_forum_node_update($node) { |
| 128 | - switch($node->type) { |
|
| 129 | - case 'team_forum': |
|
| 128 | + switch($node->type) { |
|
| 129 | + case 'team_forum': |
|
| 130 | 130 | |
| 131 | 131 | break; |
| 132 | 132 | |
| 133 | - default: |
|
| 133 | + default: |
|
| 134 | 134 | |
| 135 | 135 | } |
| 136 | 136 | } |
@@ -140,8 +140,8 @@ discard block |
||
| 140 | 140 | * is validated (forward compatible to Drupal 7) |
| 141 | 141 | */ |
| 142 | 142 | function boincteam_forum_node_validate($node) { |
| 143 | - switch($node->type) { |
|
| 144 | - case 'team_forum': |
|
| 143 | + switch($node->type) { |
|
| 144 | + case 'team_forum': |
|
| 145 | 145 | $account = user_load($node->uid); |
| 146 | 146 | // Get tfid from node, but if empty/null, get it from the database |
| 147 | 147 | if (!($node->tfid)) { |
@@ -154,11 +154,11 @@ discard block |
||
| 154 | 154 | } |
| 155 | 155 | $team_id = boincteam_forum_lookup_nid($tfid); |
| 156 | 156 | if (!$account->team OR $account->team != $team_id) { |
| 157 | - drupal_set_message(t('Failed to add team forum topic.'), 'error'); |
|
| 158 | - drupal_goto('community/forum'); |
|
| 157 | + drupal_set_message(t('Failed to add team forum topic.'), 'error'); |
|
| 158 | + drupal_goto('community/forum'); |
|
| 159 | 159 | } |
| 160 | 160 | break; |
| 161 | - default: |
|
| 161 | + default: |
|
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | |
@@ -167,19 +167,19 @@ discard block |
||
| 167 | 167 | * is viewed (forward compatible to Drupal 7) |
| 168 | 168 | */ |
| 169 | 169 | function boincteam_forum_node_view($node) { |
| 170 | - switch($node->type) { |
|
| 171 | - case 'team_forum': |
|
| 170 | + switch($node->type) { |
|
| 171 | + case 'team_forum': |
|
| 172 | 172 | $team_id = boincteam_forum_lookup_nid($node->tfid); |
| 173 | 173 | $public_forum = boincteam_forum_is_public($node->tfid); |
| 174 | 174 | $is_member = boincteam_is_member($team_id); |
| 175 | 175 | $is_global_moderator = boincteam_forum_is_global_moderator(); |
| 176 | 176 | if (!$public_forum AND !$is_member AND !$is_global_moderator) { |
| 177 | - drupal_not_found(); |
|
| 178 | - module_invoke_all('exit'); |
|
| 179 | - exit(); |
|
| 177 | + drupal_not_found(); |
|
| 178 | + module_invoke_all('exit'); |
|
| 179 | + exit(); |
|
| 180 | 180 | } |
| 181 | 181 | break; |
| 182 | - default: |
|
| 182 | + default: |
|
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | 185 | |
@@ -187,17 +187,17 @@ discard block |
||
| 187 | 187 | * Implementation of hook_views_api(). |
| 188 | 188 | */ |
| 189 | 189 | function boincteam_forum_views_api() { |
| 190 | - return array( |
|
| 190 | + return array( |
|
| 191 | 191 | 'api' => 2.0, |
| 192 | 192 | 'path' => drupal_get_path('module', 'boincteam_forum') |
| 193 | - ); |
|
| 193 | + ); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /** |
| 197 | 197 | * Implementation of hook_perm() |
| 198 | 198 | */ |
| 199 | 199 | function boincteam_forum_perm() { |
| 200 | - return array('manage boincteam forum'); |
|
| 200 | + return array('manage boincteam forum'); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | |
@@ -209,43 +209,43 @@ discard block |
||
| 209 | 209 | * Check if the user has global access to moderate team forums |
| 210 | 210 | */ |
| 211 | 211 | function boincteam_forum_is_global_moderator() { |
| 212 | - global $user; |
|
| 213 | - return user_access('manage boincteam forum'); |
|
| 212 | + global $user; |
|
| 213 | + return user_access('manage boincteam forum'); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | /* |
| 217 | 217 | * Check if any forums for a team are public |
| 218 | 218 | */ |
| 219 | 219 | function boincteam_forum_is_any_public($team_id) { |
| 220 | - $forums = boincteam_forum_list($team_id); |
|
| 221 | - foreach ($forums as $forum) { |
|
| 220 | + $forums = boincteam_forum_list($team_id); |
|
| 221 | + foreach ($forums as $forum) { |
|
| 222 | 222 | if ($forum->public) { |
| 223 | - return TRUE; |
|
| 223 | + return TRUE; |
|
| 224 | 224 | } |
| 225 | - } |
|
| 226 | - return FALSE; |
|
| 225 | + } |
|
| 226 | + return FALSE; |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /* |
| 230 | 230 | * Check if a team forum should be visible to everyone |
| 231 | 231 | */ |
| 232 | 232 | function boincteam_forum_is_public($tfid) { |
| 233 | - return db_result(db_query(" |
|
| 233 | + return db_result(db_query(" |
|
| 234 | 234 | SELECT public FROM {boincteam_forum} WHERE tfid=%d", $tfid |
| 235 | - )); |
|
| 235 | + )); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /* |
| 239 | 239 | * Load the forums for a team, if any exist |
| 240 | 240 | */ |
| 241 | 241 | function boincteam_forum_list($team_id = NULL) { |
| 242 | - if (!$team_id) { |
|
| 242 | + if (!$team_id) { |
|
| 243 | 243 | global $user; |
| 244 | 244 | $account = user_load($user->uid); |
| 245 | 245 | $team_id = $account->team; |
| 246 | - } |
|
| 247 | - $team_forums = array(); |
|
| 248 | - if ($team_id) { |
|
| 246 | + } |
|
| 247 | + $team_forums = array(); |
|
| 248 | + if ($team_id) { |
|
| 249 | 249 | // Load any team forum objects for the user's team |
| 250 | 250 | $result = db_query(" |
| 251 | 251 | SELECT tfid, nid, title, description, created, updated, public, |
@@ -255,26 +255,26 @@ discard block |
||
| 255 | 255 | $row = 0; |
| 256 | 256 | while ($team_forum = db_fetch_object($result)) { |
| 257 | 257 | |
| 258 | - $team_forum->link = url("community/teams/{$team_id}/forum/{$team_forum->tfid}"); |
|
| 259 | - $team_forum->zebra = $row % 2 ? 'even' : 'odd'; |
|
| 260 | - $team_forum->new_topics = 0; // TODO: Track user views of team topics |
|
| 261 | - $team_forum->new_text = ''; |
|
| 262 | - $team_forum->new_url = ''; |
|
| 263 | - $team_forum->num_topics = db_result(db_query(" |
|
| 258 | + $team_forum->link = url("community/teams/{$team_id}/forum/{$team_forum->tfid}"); |
|
| 259 | + $team_forum->zebra = $row % 2 ? 'even' : 'odd'; |
|
| 260 | + $team_forum->new_topics = 0; // TODO: Track user views of team topics |
|
| 261 | + $team_forum->new_text = ''; |
|
| 262 | + $team_forum->new_url = ''; |
|
| 263 | + $team_forum->num_topics = db_result(db_query(" |
|
| 264 | 264 | SELECT COUNT(nid) FROM {boincteam_forum_node} |
| 265 | 265 | WHERE tfid = %d", |
| 266 | 266 | $team_forum->tfid |
| 267 | - )); |
|
| 268 | - $team_forum->num_posts = db_result(db_query(" |
|
| 267 | + )); |
|
| 268 | + $team_forum->num_posts = db_result(db_query(" |
|
| 269 | 269 | SELECT COALESCE(SUM(ncs.comment_count),0) + COUNT(ncs.nid) |
| 270 | 270 | FROM {boincteam_forum_node} bfn |
| 271 | 271 | JOIN {node_comment_statistics} ncs ON ncs.nid = bfn.nid |
| 272 | 272 | JOIN {node} n ON n.nid = ncs.nid |
| 273 | 273 | WHERE bfn.tfid = %d AND n.status = 1", |
| 274 | 274 | $team_forum->tfid |
| 275 | - )); |
|
| 276 | - $last_post = new stdClass(); |
|
| 277 | - $last_post->timestamp = db_result(db_query(" |
|
| 275 | + )); |
|
| 276 | + $last_post = new stdClass(); |
|
| 277 | + $last_post->timestamp = db_result(db_query(" |
|
| 278 | 278 | SELECT ncs.last_comment_timestamp FROM {node} n |
| 279 | 279 | INNER JOIN {boincteam_forum_node} bfn |
| 280 | 280 | INNER JOIN {node_comment_statistics} ncs ON n.nid = bfn.nid AND n.nid = ncs.nid |
@@ -282,36 +282,36 @@ discard block |
||
| 282 | 282 | ORDER BY ncs.last_comment_timestamp DESC |
| 283 | 283 | LIMIT 1", |
| 284 | 284 | $team_forum->tfid |
| 285 | - )); |
|
| 286 | - $team_forum->last_reply = theme('forum_submitted', ($last_post->timestamp) ? $last_post : NULL); |
|
| 287 | - $team_forums[$team_forum->tfid] = $team_forum; |
|
| 288 | - $row++; |
|
| 285 | + )); |
|
| 286 | + $team_forum->last_reply = theme('forum_submitted', ($last_post->timestamp) ? $last_post : NULL); |
|
| 287 | + $team_forums[$team_forum->tfid] = $team_forum; |
|
| 288 | + $row++; |
|
| 289 | 289 | } |
| 290 | - } |
|
| 291 | - return $team_forums; |
|
| 290 | + } |
|
| 291 | + return $team_forums; |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | /* |
| 295 | 295 | * Load a team forum by ID |
| 296 | 296 | */ |
| 297 | 297 | function boincteam_forum_load($tfid) { |
| 298 | - // Load any team forum objects for the user's team |
|
| 299 | - $result = db_query(" |
|
| 298 | + // Load any team forum objects for the user's team |
|
| 299 | + $result = db_query(" |
|
| 300 | 300 | SELECT tfid, nid, title, description, created, updated, public, |
| 301 | 301 | min_time_between_posts, min_total_credit_to_post, min_avg_credit_to_post |
| 302 | 302 | FROM {boincteam_forum} WHERE tfid=%d", $tfid |
| 303 | - ); |
|
| 304 | - return db_fetch_object($result); |
|
| 303 | + ); |
|
| 304 | + return db_fetch_object($result); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /* |
| 308 | 308 | * Look up the team ID for a given team forum |
| 309 | 309 | */ |
| 310 | 310 | function boincteam_forum_lookup_nid($tfid) { |
| 311 | - return db_result(db_query(" |
|
| 311 | + return db_result(db_query(" |
|
| 312 | 312 | SELECT nid FROM {boincteam_forum} |
| 313 | 313 | WHERE tfid=%d", $tfid |
| 314 | - )); |
|
| 314 | + )); |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | |
@@ -323,80 +323,80 @@ discard block |
||
| 323 | 323 | * Create team forum form |
| 324 | 324 | */ |
| 325 | 325 | function boincteam_forum_create_form_panel() { |
| 326 | - $output = ''; |
|
| 327 | - $output .= '<h2 class="pane-title">' . bts('Create team message board', array(), NULL, 'boinc:team-forum') |
|
| 326 | + $output = ''; |
|
| 327 | + $output .= '<h2 class="pane-title">' . bts('Create team message board', array(), NULL, 'boinc:team-forum') |
|
| 328 | 328 | . '</h2>'; |
| 329 | - $output .= drupal_get_form('boincteam_forum_create_form'); |
|
| 329 | + $output .= drupal_get_form('boincteam_forum_create_form'); |
|
| 330 | 330 | |
| 331 | - return $output; |
|
| 331 | + return $output; |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | /** |
| 335 | 335 | * Edit team forum form |
| 336 | 336 | */ |
| 337 | 337 | function boincteam_forum_edit_form_panel($tfid) { |
| 338 | - $team_forum = boincteam_forum_load($tfid); |
|
| 339 | - $output = ''; |
|
| 340 | - $output .= '<h2 class="pane-title">' . bts('Edit message board', array(), NULL, 'boinc:team-forum') . ': ' . |
|
| 338 | + $team_forum = boincteam_forum_load($tfid); |
|
| 339 | + $output = ''; |
|
| 340 | + $output .= '<h2 class="pane-title">' . bts('Edit message board', array(), NULL, 'boinc:team-forum') . ': ' . |
|
| 341 | 341 | $team_forum->title . '</h2>'; |
| 342 | - $output .= drupal_get_form('boincteam_forum_edit_form', $tfid); |
|
| 342 | + $output .= drupal_get_form('boincteam_forum_edit_form', $tfid); |
|
| 343 | 343 | |
| 344 | - return $output; |
|
| 344 | + return $output; |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | /** |
| 348 | 348 | * Link to team forums |
| 349 | 349 | */ |
| 350 | 350 | function boincteam_forum_link_panel($team_id) { |
| 351 | - $show_public_only = ( |
|
| 351 | + $show_public_only = ( |
|
| 352 | 352 | !boincteam_is_member($team_id) AND |
| 353 | 353 | !boincteam_forum_is_global_moderator() |
| 354 | - ); |
|
| 355 | - $forums = boincteam_forum_list($team_id); |
|
| 356 | - $output = ''; |
|
| 357 | - $output .= '<h2 class="pane-title">' . bts('Team forum', array(), NULL, 'boinc:team-forum') . '</h2>'; |
|
| 358 | - $output .= '<p>' |
|
| 354 | + ); |
|
| 355 | + $forums = boincteam_forum_list($team_id); |
|
| 356 | + $output = ''; |
|
| 357 | + $output .= '<h2 class="pane-title">' . bts('Team forum', array(), NULL, 'boinc:team-forum') . '</h2>'; |
|
| 358 | + $output .= '<p>' |
|
| 359 | 359 | . bts('A discussion forum has been set up for team members.', array(), NULL, 'boinc:team-forum') |
| 360 | 360 | . '</p>'; |
| 361 | - $output .= '<ul class="tab-list action-list">'; |
|
| 362 | - foreach ($forums as $forum) { |
|
| 361 | + $output .= '<ul class="tab-list action-list">'; |
|
| 362 | + foreach ($forums as $forum) { |
|
| 363 | 363 | if (!$show_public_only OR $forum->public) { |
| 364 | - $output .= ' <li class="tab primary">' . |
|
| 364 | + $output .= ' <li class="tab primary">' . |
|
| 365 | 365 | l( |
| 366 | - //$forum->title, |
|
| 367 | - bts('Enter forum', array(), NULL, 'boinc:team-forum'), |
|
| 368 | - "community/teams/{$team_id}/forum/{$forum->tfid}" |
|
| 366 | + //$forum->title, |
|
| 367 | + bts('Enter forum', array(), NULL, 'boinc:team-forum'), |
|
| 368 | + "community/teams/{$team_id}/forum/{$forum->tfid}" |
|
| 369 | 369 | ) . '</li>'; |
| 370 | - // Since we're only supporting one team forum for now, we've labeled the |
|
| 371 | - // link in a generic way above and will now just break out of the loop |
|
| 372 | - break; |
|
| 370 | + // Since we're only supporting one team forum for now, we've labeled the |
|
| 371 | + // link in a generic way above and will now just break out of the loop |
|
| 372 | + break; |
|
| 373 | 373 | } |
| 374 | - } |
|
| 375 | - $output .= '</ul>'; |
|
| 376 | - return $output; |
|
| 374 | + } |
|
| 375 | + $output .= '</ul>'; |
|
| 376 | + return $output; |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | /** |
| 380 | 380 | * General info about team forums |
| 381 | 381 | */ |
| 382 | 382 | function boincteam_forum_topic_overview_panel($nid = NULL) { |
| 383 | - $output = ''; |
|
| 384 | - $output .= '<h2 class="pane-title">' . bts('About message boards', array(), NULL, 'boinc:team-forum') . '</h2>'; |
|
| 385 | - $output .= '<div>'; |
|
| 386 | - if ($nid) { |
|
| 383 | + $output = ''; |
|
| 384 | + $output .= '<h2 class="pane-title">' . bts('About message boards', array(), NULL, 'boinc:team-forum') . '</h2>'; |
|
| 385 | + $output .= '<div>'; |
|
| 386 | + if ($nid) { |
|
| 387 | 387 | $team = node_load($nid); |
| 388 | 388 | $output .= '<p>' . bts('You may create a message board for use by @team', |
| 389 | - array('@team' => $team->title), NULL, 'boinc:team-forum') . ':</p>'; |
|
| 390 | - } |
|
| 391 | - else { |
|
| 389 | + array('@team' => $team->title), NULL, 'boinc:team-forum') . ':</p>'; |
|
| 390 | + } |
|
| 391 | + else { |
|
| 392 | 392 | $output .= '<p>' . bts('This is a team-only message board', array(), NULL, 'boinc:team-forum') . ':</p>'; |
| 393 | - } |
|
| 394 | - $output .= '<ul>'; |
|
| 395 | - $output .= ' <li>' . bts('Only members may post', array(), NULL, 'boinc:team-forum') . '</li>'; |
|
| 396 | - $output .= ' <li>' . bts('Only members may read (optional)', array(), NULL, 'boinc:team-forum') . '</li>'; |
|
| 397 | - $output .= ' <li>' . bts('Founder & Team Admins have moderator privileges', array(), NULL, 'boinc:team-forum') . |
|
| 393 | + } |
|
| 394 | + $output .= '<ul>'; |
|
| 395 | + $output .= ' <li>' . bts('Only members may post', array(), NULL, 'boinc:team-forum') . '</li>'; |
|
| 396 | + $output .= ' <li>' . bts('Only members may read (optional)', array(), NULL, 'boinc:team-forum') . '</li>'; |
|
| 397 | + $output .= ' <li>' . bts('Founder & Team Admins have moderator privileges', array(), NULL, 'boinc:team-forum') . |
|
| 398 | 398 | '</li>'; |
| 399 | - $output .= '</ul>'; |
|
| 400 | - $output .= '</div>'; |
|
| 401 | - return $output; |
|
| 399 | + $output .= '</ul>'; |
|
| 400 | + $output .= '</div>'; |
|
| 401 | + return $output; |
|
| 402 | 402 | } |
@@ -26,16 +26,16 @@ discard block |
||
| 26 | 26 | * Implementation of hook_comment(); |
| 27 | 27 | */ |
| 28 | 28 | function flag_comment_notify_comment(&$a1, $op) { |
| 29 | - switch ($op) { |
|
| 30 | - case 'insert': |
|
| 29 | + switch ($op) { |
|
| 30 | + case 'insert': |
|
| 31 | 31 | module_load_include('inc', 'drupal_queue', 'drupal_queue'); |
| 32 | 32 | $queue = DrupalQueue::get('flag_comment_notify'); |
| 33 | 33 | $subscribed_users = array_keys((array) flag_get_content_flags('node', $a1['nid'], 'subscriptions')); |
| 34 | 34 | foreach ($subscribed_users as $uid) { |
| 35 | - $queue->createItem(array('uid' => $uid, 'cid' => (int) $a1['cid'])); |
|
| 35 | + $queue->createItem(array('uid' => $uid, 'cid' => (int) $a1['cid'])); |
|
| 36 | 36 | } |
| 37 | 37 | break; |
| 38 | - default: |
|
| 38 | + default: |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
@@ -43,12 +43,12 @@ discard block |
||
| 43 | 43 | * Implementation of hook_cron_queue_info() |
| 44 | 44 | */ |
| 45 | 45 | function flag_comment_notify_cron_queue_info() { |
| 46 | - $queues = array(); |
|
| 47 | - $queues['flag_comment_notify'] = array( |
|
| 46 | + $queues = array(); |
|
| 47 | + $queues['flag_comment_notify'] = array( |
|
| 48 | 48 | 'worker callback' => 'flag_comment_notify_send_notification', |
| 49 | 49 | 'time' => 60, |
| 50 | - ); |
|
| 51 | - return $queues; |
|
| 50 | + ); |
|
| 51 | + return $queues; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -57,44 +57,44 @@ discard block |
||
| 57 | 57 | * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 58 | 58 | |
| 59 | 59 | function flag_comment_notify_send_notification($data) { |
| 60 | - $account = user_load($data['uid']); |
|
| 61 | - $comment = _comment_load($data['cid']); |
|
| 62 | - $node = node_load($comment->nid); |
|
| 63 | - $author = user_load($comment->uid); |
|
| 64 | - if ($account->mail AND $node->nid) { |
|
| 60 | + $account = user_load($data['uid']); |
|
| 61 | + $comment = _comment_load($data['cid']); |
|
| 62 | + $node = node_load($comment->nid); |
|
| 63 | + $author = user_load($comment->uid); |
|
| 64 | + if ($account->mail AND $node->nid) { |
|
| 65 | 65 | // Don't send notifications to the author of the comment |
| 66 | 66 | if ($account->uid != $author->uid) { |
| 67 | - $params['account'] = $account; |
|
| 68 | - $params['comment'] = $comment; |
|
| 69 | - $params['node'] = $node; |
|
| 70 | - $params['author'] = $author; |
|
| 71 | - drupal_mail('flag_comment_notify', 'comment_posted', $account->mail, |
|
| 67 | + $params['account'] = $account; |
|
| 68 | + $params['comment'] = $comment; |
|
| 69 | + $params['node'] = $node; |
|
| 70 | + $params['author'] = $author; |
|
| 71 | + drupal_mail('flag_comment_notify', 'comment_posted', $account->mail, |
|
| 72 | 72 | user_preferred_language($account), $params); |
| 73 | 73 | } |
| 74 | - } |
|
| 74 | + } |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | |
| 78 | 78 | function flag_comment_notify_mail($key, &$message, $params) { |
| 79 | - $language = $message['language']; |
|
| 80 | - $variables = user_mail_tokens($params['account'], $language); |
|
| 81 | - $variables['!comment_url'] = url( |
|
| 79 | + $language = $message['language']; |
|
| 80 | + $variables = user_mail_tokens($params['account'], $language); |
|
| 81 | + $variables['!comment_url'] = url( |
|
| 82 | 82 | "goto/comment/{$params['comment']->cid}", |
| 83 | 83 | array( |
| 84 | - 'absolute' => TRUE, |
|
| 84 | + 'absolute' => TRUE, |
|
| 85 | 85 | ) |
| 86 | - ); |
|
| 87 | - $variables['!topic_name'] = $params['node']->title; |
|
| 88 | - $variables['!author'] = $params['author']->name; |
|
| 89 | - switch($key) { |
|
| 90 | - case 'comment_posted': |
|
| 86 | + ); |
|
| 87 | + $variables['!topic_name'] = $params['node']->title; |
|
| 88 | + $variables['!author'] = $params['author']->name; |
|
| 89 | + switch($key) { |
|
| 90 | + case 'comment_posted': |
|
| 91 | 91 | $message['subject'] = bts('!site: comment posted to "!topic_name"', $variables, |
| 92 | - $language->language, 'boinc:forum-topic-subscription-email-notification'); |
|
| 92 | + $language->language, 'boinc:forum-topic-subscription-email-notification'); |
|
| 93 | 93 | $message['body'][] = bts('!author has posted a reply to "!topic_name".', |
| 94 | - $variables, $language->language, 'boinc:forum-topic-subscription-email-notification'); |
|
| 94 | + $variables, $language->language, 'boinc:forum-topic-subscription-email-notification'); |
|
| 95 | 95 | $message['body'][] = bts("To view this topic at !site, click here: \n!comment_url", |
| 96 | - $variables, $language->language, 'boinc:forum-topic-subscription-email-notification'); |
|
| 96 | + $variables, $language->language, 'boinc:forum-topic-subscription-email-notification'); |
|
| 97 | 97 | break; |
| 98 | - default: |
|
| 98 | + default: |
|
| 99 | 99 | } |
| 100 | 100 | } |
@@ -9,40 +9,40 @@ discard block |
||
| 9 | 9 | * Implements hook_block() for Drupal 6 compatibility |
| 10 | 10 | */ |
| 11 | 11 | function comment_form_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 == 'comment_form') { |
| 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 | global $user; |
| 19 | 19 | $node = node_load($nid); |
| 20 | 20 | if ($node->comment !== 0 AND user_access('post comments', $user)) { |
| 21 | - $block['subject'] = NULL; // This should be NULL otherwise there will be duplicate h2 elements. |
|
| 22 | - $block['content'] = '<h2>' . bts('Post new comment', array(), NULL, 'boinc:forum-post-new-comment') . '</h2>'; |
|
| 23 | - $block['content'] .= drupal_get_form('comment_form', array('nid' => $nid)); |
|
| 21 | + $block['subject'] = NULL; // This should be NULL otherwise there will be duplicate h2 elements. |
|
| 22 | + $block['content'] = '<h2>' . bts('Post new comment', array(), NULL, 'boinc:forum-post-new-comment') . '</h2>'; |
|
| 23 | + $block['content'] .= drupal_get_form('comment_form', array('nid' => $nid)); |
|
| 24 | + } |
|
| 24 | 25 | } |
| 25 | - } |
|
| 26 | 26 | } |
| 27 | 27 | break; |
| 28 | - case 'list': |
|
| 28 | + case 'list': |
|
| 29 | 29 | $blocks = comment_form_block_block_info(); |
| 30 | 30 | return $blocks; |
| 31 | 31 | break; |
| 32 | - default: |
|
| 32 | + default: |
|
| 33 | 33 | } |
| 34 | - return $block; |
|
| 34 | + return $block; |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * Implements hook_block_info(). |
| 39 | 39 | */ |
| 40 | 40 | function comment_form_block_block_info() { |
| 41 | - $blocks['comment_form'] = array( |
|
| 41 | + $blocks['comment_form'] = array( |
|
| 42 | 42 | 'info' => bts('Comment form', array(), NULL, 'boinc:forum-comment-form'), |
| 43 | - ); |
|
| 43 | + ); |
|
| 44 | 44 | |
| 45 | - return $blocks; |
|
| 45 | + return $blocks; |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -81,10 +81,10 @@ discard block |
||
| 81 | 81 | * Implements hook_form_FORM_ID_alter() for block_admin_configure. |
| 82 | 82 | */ |
| 83 | 83 | function comment_form_block_form_block_admin_configure_alter(&$form, &$form_state) { |
| 84 | - if (isset($form['delta'])) { |
|
| 84 | + if (isset($form['delta'])) { |
|
| 85 | 85 | if ($form['delta']['#value'] == 'comment_form') { |
| 86 | - $form['settings']['title']['#disabled'] = TRUE; |
|
| 87 | - $form['settings']['title']['#description'] = t('The title for this block cannot be overridden.'); |
|
| 86 | + $form['settings']['title']['#disabled'] = TRUE; |
|
| 87 | + $form['settings']['title']['#description'] = t('The title for this block cannot be overridden.'); |
|
| 88 | + } |
|
| 88 | 89 | } |
| 89 | - } |
|
| 90 | 90 | } |
@@ -2,9 +2,9 @@ discard block |
||
| 2 | 2 | // $Id$ |
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | - * @file |
|
| 6 | - * Enable BOINC charting features for statistics |
|
| 7 | - */ |
|
| 5 | + * @file |
|
| 6 | + * Enable BOINC charting features for statistics |
|
| 7 | + */ |
|
| 8 | 8 | |
| 9 | 9 | |
| 10 | 10 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * |
@@ -18,10 +18,10 @@ discard block |
||
| 18 | 18 | * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | - * Implementation of hook_menu(). |
|
| 22 | - */ |
|
| 21 | + * Implementation of hook_menu(). |
|
| 22 | + */ |
|
| 23 | 23 | function boincstats_menu() { |
| 24 | - $items['admin/boinc/stats'] = array( |
|
| 24 | + $items['admin/boinc/stats'] = array( |
|
| 25 | 25 | 'title' => 'Environment: Statistics setup', |
| 26 | 26 | 'description' => 'Configure the stats system for generating charts and |
| 27 | 27 | providing cross project data.', |
@@ -30,18 +30,18 @@ discard block |
||
| 30 | 30 | 'access arguments' => array('administer site configuration'), |
| 31 | 31 | 'type' => MENU_NORMAL_ITEM, |
| 32 | 32 | 'file' => 'boincstats.admin.inc' |
| 33 | - ); |
|
| 34 | - $items['charts/user'] = array( |
|
| 33 | + ); |
|
| 34 | + $items['charts/user'] = array( |
|
| 35 | 35 | 'page callback' => 'boincstats_get_user_stats_chart', |
| 36 | 36 | 'access arguments' => array('access content'), |
| 37 | 37 | 'type' => MENU_CALLBACK |
| 38 | - ); |
|
| 39 | - $items['charts/project'] = array( |
|
| 38 | + ); |
|
| 39 | + $items['charts/project'] = array( |
|
| 40 | 40 | 'page callback' => 'boincstats_get_project_stats_chart', |
| 41 | 41 | 'access arguments' => array('access content'), |
| 42 | 42 | 'type' => MENU_CALLBACK |
| 43 | - ); |
|
| 44 | - return $items; |
|
| 43 | + ); |
|
| 44 | + return $items; |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | |
@@ -50,31 +50,31 @@ discard block |
||
| 50 | 50 | * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | - * User stats chart menu callback |
|
| 54 | - * Called to generate the daily credit status chart for a user (dashboard) |
|
| 55 | - */ |
|
| 53 | + * User stats chart menu callback |
|
| 54 | + * Called to generate the daily credit status chart for a user (dashboard) |
|
| 55 | + */ |
|
| 56 | 56 | function boincstats_get_user_stats_chart($cpid = null, $chart_size = 'medium') { |
| 57 | 57 | |
| 58 | - // pChart library inclusions |
|
| 59 | - module_load_include('php', 'boincstats', 'includes/pchart/class/pData.class'); |
|
| 60 | - module_load_include('php', 'boincstats', 'includes/pchart/class/pDraw.class'); |
|
| 61 | - module_load_include('php', 'boincstats', 'includes/pchart/class/pImage.class'); |
|
| 62 | - module_load_include('php', 'boincstats', 'includes/pchart/class/pCache.class'); |
|
| 58 | + // pChart library inclusions |
|
| 59 | + module_load_include('php', 'boincstats', 'includes/pchart/class/pData.class'); |
|
| 60 | + module_load_include('php', 'boincstats', 'includes/pchart/class/pDraw.class'); |
|
| 61 | + module_load_include('php', 'boincstats', 'includes/pchart/class/pImage.class'); |
|
| 62 | + module_load_include('php', 'boincstats', 'includes/pchart/class/pCache.class'); |
|
| 63 | 63 | |
| 64 | - init_theme(); |
|
| 65 | - global $theme_key; |
|
| 66 | - $cache_name = "{$theme_key}_"; |
|
| 64 | + init_theme(); |
|
| 65 | + global $theme_key; |
|
| 66 | + $cache_name = "{$theme_key}_"; |
|
| 67 | 67 | |
| 68 | - $dataset_size = 0; |
|
| 69 | - $chart_height = 0; |
|
| 70 | - $chart_width = 0; |
|
| 71 | - $draw_x_lines = FALSE; |
|
| 72 | - $label_x_axis = FALSE; |
|
| 68 | + $dataset_size = 0; |
|
| 69 | + $chart_height = 0; |
|
| 70 | + $chart_width = 0; |
|
| 71 | + $draw_x_lines = FALSE; |
|
| 72 | + $label_x_axis = FALSE; |
|
| 73 | 73 | |
| 74 | - $stats_xml = NULL; |
|
| 74 | + $stats_xml = NULL; |
|
| 75 | 75 | |
| 76 | - switch($chart_size) { |
|
| 77 | - case 'small': |
|
| 76 | + switch($chart_size) { |
|
| 77 | + case 'small': |
|
| 78 | 78 | $cache_name .= "{$cpid}_small"; |
| 79 | 79 | $dataset_size = 30; |
| 80 | 80 | $chart_height = 80; |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | $draw_x_lines = FALSE; |
| 84 | 84 | $label_x_axis = FALSE; |
| 85 | 85 | break; |
| 86 | - case 'medium': |
|
| 86 | + case 'medium': |
|
| 87 | 87 | default: |
| 88 | 88 | $cache_name .= $cpid; |
| 89 | 89 | $dataset_size = 60; |
@@ -91,32 +91,32 @@ discard block |
||
| 91 | 91 | $chart_width = 589; |
| 92 | 92 | $draw_x_lines = TRUE; |
| 93 | 93 | $label_x_axis = TRUE; |
| 94 | - } |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - // Sanity check for cache directory |
|
| 97 | - if (!boincstats_check_cache_dir()) { |
|
| 96 | + // Sanity check for cache directory |
|
| 97 | + if (!boincstats_check_cache_dir()) { |
|
| 98 | 98 | return; |
| 99 | - } |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - // Initialize the cache object and flush stale images |
|
| 102 | - $myCache = new pCache(array('CacheFolder' => realpath('.') . '/' . conf_path() . '/files/cache')); |
|
| 103 | - $myCache->removeOlderThan(60*60*24); |
|
| 101 | + // Initialize the cache object and flush stale images |
|
| 102 | + $myCache = new pCache(array('CacheFolder' => realpath('.') . '/' . conf_path() . '/files/cache')); |
|
| 103 | + $myCache->removeOlderThan(60*60*24); |
|
| 104 | 104 | |
| 105 | - if ($myCache->isInCache($cache_name)) { |
|
| 105 | + if ($myCache->isInCache($cache_name)) { |
|
| 106 | 106 | $myCache->strokeFromCache($cache_name); |
| 107 | - } |
|
| 108 | - else { |
|
| 107 | + } |
|
| 108 | + else { |
|
| 109 | 109 | // Initialize dataset |
| 110 | 110 | $dataset = array(); |
| 111 | 111 | $stats_xml = boincstats_get_project_stats('daily', $cpid); |
| 112 | 112 | if ($stats_xml) { |
| 113 | - // Get the last 60 days of stats for the chart |
|
| 114 | - for ($j = 30; $j < 90; $j++) { |
|
| 113 | + // Get the last 60 days of stats for the chart |
|
| 114 | + for ($j = 30; $j < 90; $j++) { |
|
| 115 | 115 | $dataset[] = (int) $stats_xml->records->record[$j]; |
| 116 | - } |
|
| 116 | + } |
|
| 117 | 117 | } |
| 118 | 118 | else { |
| 119 | - for ($i = 0; $i <= $dataset_size; $i++) $dataset[] = 0; |
|
| 119 | + for ($i = 0; $i <= $dataset_size; $i++) $dataset[] = 0; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | // Get color configuration |
@@ -145,39 +145,39 @@ discard block |
||
| 145 | 145 | // Define the chart area |
| 146 | 146 | $myPicture->setGraphArea(0, 3, $chart_width, $chart_height); |
| 147 | 147 | if ($backdrop_color) { |
| 148 | - $myPicture->drawFilledRectangle(0, 0, $chart_width, $chart_height, $backdrop_color); |
|
| 148 | + $myPicture->drawFilledRectangle(0, 0, $chart_width, $chart_height, $backdrop_color); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // Draw the scale |
| 152 | 152 | $scaleSettings = array( |
| 153 | - 'Mode' => SCALE_MODE_START0, |
|
| 154 | - 'DrawYLines' => false, |
|
| 155 | - 'DrawXLines' => $draw_x_lines, |
|
| 156 | - 'GridTicks' => 2, |
|
| 157 | - 'LabelSkip' => 9, |
|
| 158 | - 'SkippedAxisAlpha' => 0, |
|
| 159 | - 'SkippedInnerTickWidth' => 0, |
|
| 160 | - 'SkippedOuterTickWidth' => 0, |
|
| 161 | - 'AxisAlpha' => 0, |
|
| 162 | - 'InnerTickWidth' => 0, |
|
| 163 | - 'OuterTickWidth' => 0, |
|
| 164 | - 'XMargin' => 1, |
|
| 165 | - 'YMargin' => 0, |
|
| 166 | - 'Floating' => TRUE, |
|
| 167 | - 'GridR' => 200, |
|
| 168 | - 'GridG' => 200, |
|
| 169 | - 'GridB' => 200, |
|
| 170 | - 'DrawSubTicks' => false, |
|
| 171 | - 'CycleBackground' => false |
|
| 153 | + 'Mode' => SCALE_MODE_START0, |
|
| 154 | + 'DrawYLines' => false, |
|
| 155 | + 'DrawXLines' => $draw_x_lines, |
|
| 156 | + 'GridTicks' => 2, |
|
| 157 | + 'LabelSkip' => 9, |
|
| 158 | + 'SkippedAxisAlpha' => 0, |
|
| 159 | + 'SkippedInnerTickWidth' => 0, |
|
| 160 | + 'SkippedOuterTickWidth' => 0, |
|
| 161 | + 'AxisAlpha' => 0, |
|
| 162 | + 'InnerTickWidth' => 0, |
|
| 163 | + 'OuterTickWidth' => 0, |
|
| 164 | + 'XMargin' => 1, |
|
| 165 | + 'YMargin' => 0, |
|
| 166 | + 'Floating' => TRUE, |
|
| 167 | + 'GridR' => 200, |
|
| 168 | + 'GridG' => 200, |
|
| 169 | + 'GridB' => 200, |
|
| 170 | + 'DrawSubTicks' => false, |
|
| 171 | + 'CycleBackground' => false |
|
| 172 | 172 | ); |
| 173 | 173 | $myPicture->setFontProperties(array('FontSize' => 10)); |
| 174 | 174 | $myPicture->drawScale($scaleSettings); |
| 175 | 175 | |
| 176 | 176 | if ($label_x_axis) { |
| 177 | - for ($i = 5; $i >= 0; $i--) { |
|
| 177 | + for ($i = 5; $i >= 0; $i--) { |
|
| 178 | 178 | $label = ($i) ? -10*$i : 'Today'; |
| 179 | 179 | $myPicture->drawText(589-587*($i/6)-5, 2, $label, array('Align' => TEXT_ALIGN_TOPRIGHT)); |
| 180 | - } |
|
| 180 | + } |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | // Draw the area chart |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | // Render the picture (choose the best way) |
| 190 | 190 | //$myPicture->autoOutput('pictures/example.drawAreaChart.simple.png'); |
| 191 | 191 | $myPicture->stroke(); |
| 192 | - } |
|
| 192 | + } |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -197,48 +197,48 @@ discard block |
||
| 197 | 197 | * Called to generate the daily credit status chart for the whole project |
| 198 | 198 | */ |
| 199 | 199 | function boincstats_get_project_stats_chart() { |
| 200 | - // pChart library inclusions |
|
| 201 | - module_load_include('php', 'boincstats', 'includes/pchart/class/pData.class'); |
|
| 202 | - module_load_include('php', 'boincstats', 'includes/pchart/class/pDraw.class'); |
|
| 203 | - module_load_include('php', 'boincstats', 'includes/pchart/class/pImage.class'); |
|
| 204 | - module_load_include('php', 'boincstats', 'includes/pchart/class/pCache.class'); |
|
| 205 | - |
|
| 206 | - init_theme(); |
|
| 207 | - global $theme_key; |
|
| 208 | - $cache_name = "{$theme_key}_project_chart"; |
|
| 209 | - |
|
| 210 | - $color_keys = array('R', 'G', 'B'); |
|
| 211 | - |
|
| 212 | - // Get color configuration |
|
| 213 | - $palette_color_hex = theme_get_setting('boinc_stats_chart_color'); |
|
| 214 | - $palette_color = array_combine($color_keys, sscanf($palette_color_hex, "#%02x%02x%02x")); |
|
| 215 | - $backdrop_color_hex = theme_get_setting('boinc_stats_chart_bcolor'); |
|
| 216 | - $backdrop_color = array_combine($color_keys, sscanf($backdrop_color_hex, "#%02x%02x%02x")); |
|
| 217 | - |
|
| 218 | - // Sanity check for cache directory |
|
| 219 | - if (!boincstats_check_cache_dir()) { |
|
| 200 | + // pChart library inclusions |
|
| 201 | + module_load_include('php', 'boincstats', 'includes/pchart/class/pData.class'); |
|
| 202 | + module_load_include('php', 'boincstats', 'includes/pchart/class/pDraw.class'); |
|
| 203 | + module_load_include('php', 'boincstats', 'includes/pchart/class/pImage.class'); |
|
| 204 | + module_load_include('php', 'boincstats', 'includes/pchart/class/pCache.class'); |
|
| 205 | + |
|
| 206 | + init_theme(); |
|
| 207 | + global $theme_key; |
|
| 208 | + $cache_name = "{$theme_key}_project_chart"; |
|
| 209 | + |
|
| 210 | + $color_keys = array('R', 'G', 'B'); |
|
| 211 | + |
|
| 212 | + // Get color configuration |
|
| 213 | + $palette_color_hex = theme_get_setting('boinc_stats_chart_color'); |
|
| 214 | + $palette_color = array_combine($color_keys, sscanf($palette_color_hex, "#%02x%02x%02x")); |
|
| 215 | + $backdrop_color_hex = theme_get_setting('boinc_stats_chart_bcolor'); |
|
| 216 | + $backdrop_color = array_combine($color_keys, sscanf($backdrop_color_hex, "#%02x%02x%02x")); |
|
| 217 | + |
|
| 218 | + // Sanity check for cache directory |
|
| 219 | + if (!boincstats_check_cache_dir()) { |
|
| 220 | 220 | return; |
| 221 | - } |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - // Initialize the cache object and flush stale images |
|
| 224 | - $myCache = new pCache(array('CacheFolder' => realpath('.') . '/' . conf_path() . '/files/cache')); |
|
| 225 | - $myCache->removeOlderThan(60*60*24); |
|
| 223 | + // Initialize the cache object and flush stale images |
|
| 224 | + $myCache = new pCache(array('CacheFolder' => realpath('.') . '/' . conf_path() . '/files/cache')); |
|
| 225 | + $myCache->removeOlderThan(60*60*24); |
|
| 226 | 226 | |
| 227 | - if ($myCache->isInCache($cache_name)) { |
|
| 227 | + if ($myCache->isInCache($cache_name)) { |
|
| 228 | 228 | $myCache->strokeFromCache($cache_name); |
| 229 | - } |
|
| 230 | - else { |
|
| 229 | + } |
|
| 230 | + else { |
|
| 231 | 231 | // Initialize dataset |
| 232 | 232 | $dataset = array(); |
| 233 | 233 | $stats_xml = boincstats_get_project_stats('daily'); |
| 234 | 234 | if ($stats_xml) { |
| 235 | - // Get the last 60 days of stats for the chart |
|
| 236 | - for ($j = 30; $j < 90; $j++) { |
|
| 235 | + // Get the last 60 days of stats for the chart |
|
| 236 | + for ($j = 30; $j < 90; $j++) { |
|
| 237 | 237 | $dataset[] = (int) $stats_xml->records->record[$j]; |
| 238 | - } |
|
| 238 | + } |
|
| 239 | 239 | } |
| 240 | 240 | else { |
| 241 | - for ($i = 0; $i <= 30; $i++) $dataset[] = 0; |
|
| 241 | + for ($i = 0; $i <= 30; $i++) $dataset[] = 0; |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | // Create and populate the pData object |
@@ -263,25 +263,25 @@ discard block |
||
| 263 | 263 | |
| 264 | 264 | // Draw the scale |
| 265 | 265 | $scaleSettings = array( |
| 266 | - 'Mode' => SCALE_MODE_START0, |
|
| 267 | - 'DrawYLines' => false, |
|
| 268 | - 'DrawXLines' => false, |
|
| 269 | - 'GridTicks' => 2, |
|
| 270 | - 'LabelSkip' => 9, |
|
| 271 | - 'SkippedAxisAlpha' => 0, |
|
| 272 | - 'SkippedInnerTickWidth' => 0, |
|
| 273 | - 'SkippedOuterTickWidth' => 0, |
|
| 274 | - 'AxisAlpha' => 0, |
|
| 275 | - 'InnerTickWidth' => 0, |
|
| 276 | - 'OuterTickWidth' => 0, |
|
| 277 | - 'XMargin' => 1, |
|
| 278 | - 'YMargin' => 0, |
|
| 279 | - 'Floating' => TRUE, |
|
| 280 | - 'GridR' => 200, |
|
| 281 | - 'GridG' => 200, |
|
| 282 | - 'GridB' => 200, |
|
| 283 | - 'DrawSubTicks' => false, |
|
| 284 | - 'CycleBackground' => false |
|
| 266 | + 'Mode' => SCALE_MODE_START0, |
|
| 267 | + 'DrawYLines' => false, |
|
| 268 | + 'DrawXLines' => false, |
|
| 269 | + 'GridTicks' => 2, |
|
| 270 | + 'LabelSkip' => 9, |
|
| 271 | + 'SkippedAxisAlpha' => 0, |
|
| 272 | + 'SkippedInnerTickWidth' => 0, |
|
| 273 | + 'SkippedOuterTickWidth' => 0, |
|
| 274 | + 'AxisAlpha' => 0, |
|
| 275 | + 'InnerTickWidth' => 0, |
|
| 276 | + 'OuterTickWidth' => 0, |
|
| 277 | + 'XMargin' => 1, |
|
| 278 | + 'YMargin' => 0, |
|
| 279 | + 'Floating' => TRUE, |
|
| 280 | + 'GridR' => 200, |
|
| 281 | + 'GridG' => 200, |
|
| 282 | + 'GridB' => 200, |
|
| 283 | + 'DrawSubTicks' => false, |
|
| 284 | + 'CycleBackground' => false |
|
| 285 | 285 | ); |
| 286 | 286 | $myPicture->setFontProperties(array('FontSize' => 10)); |
| 287 | 287 | $myPicture->drawScale($scaleSettings); |
@@ -300,41 +300,41 @@ discard block |
||
| 300 | 300 | // Render the picture (choose the best way) |
| 301 | 301 | //$myPicture->autoOutput('pictures/example.drawAreaChart.simple.png'); |
| 302 | 302 | $myPicture->stroke(); |
| 303 | - } |
|
| 303 | + } |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /* |
| 307 | 307 | * |
| 308 | 308 | */ |
| 309 | 309 | function boincstats_check_cache_dir($cache_path = 'files/cache') { |
| 310 | - $cache_dir = realpath('.') . '/' . conf_path() . '/' . $cache_path; |
|
| 311 | - if (!is_writeable($cache_dir)) { |
|
| 310 | + $cache_dir = realpath('.') . '/' . conf_path() . '/' . $cache_path; |
|
| 311 | + if (!is_writeable($cache_dir)) { |
|
| 312 | 312 | if (!is_dir($cache_dir)) { |
| 313 | - if (!is_writeable(dirname($cache_dir))) { |
|
| 313 | + if (!is_writeable(dirname($cache_dir))) { |
|
| 314 | 314 | // If the parent "files" dir isn't even writeable... |
| 315 | 315 | watchdog('boincstats', '@parent_dir directory is not writeable. This |
| 316 | 316 | directory must be writeable by the web server.', |
| 317 | - array('@parent_dir' => dirname($cache_dir)), WATCHDOG_ERROR); |
|
| 317 | + array('@parent_dir' => dirname($cache_dir)), WATCHDOG_ERROR); |
|
| 318 | 318 | return FALSE; |
| 319 | - } |
|
| 320 | - else { |
|
| 319 | + } |
|
| 320 | + else { |
|
| 321 | 321 | // Create the cache dir |
| 322 | 322 | if (!mkdir($cache_dir, 0775)) { |
| 323 | - watchdog('boincstats', 'Failed to create @cache_dir directory. Check |
|
| 323 | + watchdog('boincstats', 'Failed to create @cache_dir directory. Check |
|
| 324 | 324 | filesystem permissions...?', |
| 325 | 325 | array('@cache_dir' => $cache_dir), WATCHDOG_ERROR); |
| 326 | - return FALSE; |
|
| 326 | + return FALSE; |
|
| 327 | + } |
|
| 327 | 328 | } |
| 328 | - } |
|
| 329 | 329 | } |
| 330 | 330 | else { |
| 331 | - watchdog('boincstats', 'Cache directory at @cache_dir is not writeable. |
|
| 331 | + watchdog('boincstats', 'Cache directory at @cache_dir is not writeable. |
|
| 332 | 332 | Please allow webserver write access.', |
| 333 | 333 | array('@cache_dir' => $cache_dir), WATCHDOG_ERROR); |
| 334 | - return FALSE; |
|
| 334 | + return FALSE; |
|
| 335 | 335 | } |
| 336 | - } |
|
| 337 | - return TRUE; |
|
| 336 | + } |
|
| 337 | + return TRUE; |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | /* |
@@ -342,87 +342,87 @@ discard block |
||
| 342 | 342 | */ |
| 343 | 343 | function boincstats_get_project_stats($type = 'total', $cpid = NULL) { |
| 344 | 344 | |
| 345 | - // Determine the stats environment |
|
| 346 | - boincstats_check_configuration(); |
|
| 347 | - $stats_server = variable_get('boinc_stats_server', ''); |
|
| 348 | - $stats_rpc = variable_get('boinc_stats_project_credit_history_rpc', ''); |
|
| 349 | - $project_id = variable_get('boinc_stats_remote_project_id', ''); |
|
| 345 | + // Determine the stats environment |
|
| 346 | + boincstats_check_configuration(); |
|
| 347 | + $stats_server = variable_get('boinc_stats_server', ''); |
|
| 348 | + $stats_rpc = variable_get('boinc_stats_project_credit_history_rpc', ''); |
|
| 349 | + $project_id = variable_get('boinc_stats_remote_project_id', ''); |
|
| 350 | 350 | |
| 351 | - $get = array( |
|
| 351 | + $get = array( |
|
| 352 | 352 | 'id' => $project_id |
| 353 | - ); |
|
| 354 | - switch ($type) { |
|
| 355 | - case 'daily': |
|
| 353 | + ); |
|
| 354 | + switch ($type) { |
|
| 355 | + case 'daily': |
|
| 356 | 356 | $get['daily'] = NULL; |
| 357 | 357 | break; |
| 358 | - case 'total': |
|
| 358 | + case 'total': |
|
| 359 | 359 | default: |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - if ($cpid) { |
|
| 362 | + if ($cpid) { |
|
| 363 | 363 | // If a user CPID has been provided, limit scope to that user |
| 364 | 364 | $stats_rpc = variable_get('boinc_stats_user_credit_history_rpc', ''); |
| 365 | 365 | $get['cpid'] = $cpid; |
| 366 | - } |
|
| 366 | + } |
|
| 367 | 367 | |
| 368 | - // Construct query string |
|
| 369 | - $args = array(); |
|
| 370 | - foreach ($get as $arg => $value) { |
|
| 368 | + // Construct query string |
|
| 369 | + $args = array(); |
|
| 370 | + foreach ($get as $arg => $value) { |
|
| 371 | 371 | if ($value !== NULL) { |
| 372 | - $args[] = "{$arg}=" . rawurlencode($value); |
|
| 372 | + $args[] = "{$arg}=" . rawurlencode($value); |
|
| 373 | 373 | } |
| 374 | 374 | else { |
| 375 | - $args[] = $arg; |
|
| 375 | + $args[] = $arg; |
|
| 376 | 376 | } |
| 377 | - } |
|
| 378 | - $query = '?' . implode('&', $args); |
|
| 377 | + } |
|
| 378 | + $query = '?' . implode('&', $args); |
|
| 379 | 379 | |
| 380 | - // Load XML from RPC |
|
| 381 | - $stats_xml = NULL; |
|
| 382 | - $target_url = "http://{$stats_server}/{$stats_rpc}{$query}"; |
|
| 383 | - $result = drupal_http_request($target_url); |
|
| 384 | - if (in_array($result->code, array(200, 304)) || in_array($result->redirect_code, array(200, 304))) { |
|
| 380 | + // Load XML from RPC |
|
| 381 | + $stats_xml = NULL; |
|
| 382 | + $target_url = "http://{$stats_server}/{$stats_rpc}{$query}"; |
|
| 383 | + $result = drupal_http_request($target_url); |
|
| 384 | + if (in_array($result->code, array(200, 304)) || in_array($result->redirect_code, array(200, 304))) { |
|
| 385 | 385 | $stats_xml = simplexml_load_string($result->data); |
| 386 | - } |
|
| 387 | - watchdog('boincstats', $target_url); |
|
| 388 | - return $stats_xml; |
|
| 386 | + } |
|
| 387 | + watchdog('boincstats', $target_url); |
|
| 388 | + return $stats_xml; |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | /* |
| 392 | 392 | * |
| 393 | 393 | */ |
| 394 | 394 | function boincstats_get_project_total_credit() { |
| 395 | - $stats_xml = boincstats_get_project_stats(); |
|
| 396 | - $last_record = end($stats_xml->records->record); |
|
| 397 | - return ($last_record) ? (int) $last_record : 0; |
|
| 395 | + $stats_xml = boincstats_get_project_stats(); |
|
| 396 | + $last_record = end($stats_xml->records->record); |
|
| 397 | + return ($last_record) ? (int) $last_record : 0; |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | /* |
| 401 | 401 | * |
| 402 | 402 | */ |
| 403 | 403 | function boincstats_get_project_avg_credit() { |
| 404 | - $stats_xml = boincstats_get_project_stats(); |
|
| 405 | - return (isset($stats_xml->recent_avg)) ? $stats_xml->recent_avg : 0; |
|
| 404 | + $stats_xml = boincstats_get_project_stats(); |
|
| 405 | + return (isset($stats_xml->recent_avg)) ? $stats_xml->recent_avg : 0; |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | /* |
| 409 | 409 | * |
| 410 | 410 | */ |
| 411 | 411 | function boincstats_credit_to_ghours($credit) { |
| 412 | - return $credit / (100 * 365); |
|
| 412 | + return $credit / (100 * 365); |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | /* |
| 416 | 416 | * |
| 417 | 417 | */ |
| 418 | 418 | function boincstats_credit_to_flops($credit, $prefix = 0) { |
| 419 | - $factor = array( |
|
| 419 | + $factor = array( |
|
| 420 | 420 | '0' => 0, |
| 421 | 421 | 'g' => 3, |
| 422 | 422 | 't' => 6, |
| 423 | 423 | 'p' => 9 |
| 424 | - ); |
|
| 425 | - return $credit / (pow(10, (int) $factor[$prefix]) / 10); |
|
| 424 | + ); |
|
| 425 | + return $credit / (pow(10, (int) $factor[$prefix]) / 10); |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | |
@@ -431,22 +431,22 @@ discard block |
||
| 431 | 431 | * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 432 | 432 | |
| 433 | 433 | function boincstats_get_project_stats_overview($type = 'basic') { |
| 434 | - global $base_path; |
|
| 435 | - $output = ''; |
|
| 436 | - switch ($type) { |
|
| 437 | - case 'basic': |
|
| 434 | + global $base_path; |
|
| 435 | + $output = ''; |
|
| 436 | + switch ($type) { |
|
| 437 | + case 'basic': |
|
| 438 | 438 | $output .= '<div class="overlay"><span>(' . bts('Credits per day', array(), NULL, 'boinc:front-page') . ')</span></div>' . "\n"; |
| 439 | 439 | $output .= '<div class="chart"><img src="' . $base_path . 'charts/project" /></div>' . "\n"; |
| 440 | 440 | break; |
| 441 | - case 'detailed': |
|
| 441 | + case 'detailed': |
|
| 442 | 442 | $output .= '<div class="stats"><label>' . bts('Total G-hours', array(), NULL, 'boinc:front-page') . ': </label><span>' . number_format(boincstats_credit_to_ghours(boincstats_get_project_total_credit())) . '</span></div>' . "\n"; |
| 443 | 443 | $output .= '<div class="stats"><label>' . bts('Avg TFlops', array(), NULL, 'boinc:front-page') . ': </label><span>' . number_format(boincstats_credit_to_flops(boincstats_get_project_avg_credit(), 't')) . '</span></div>' . "\n"; |
| 444 | 444 | //$output .= '<div class="stats"><a href="#">' . bts('Pending credits', array(), NULL, 'boinc:front-page') . '</a></div>' . "\n"; |
| 445 | 445 | $output .= '<div class="chart"><img src="' . $base_path . 'charts/project" /></div>' . "\n"; |
| 446 | 446 | break; |
| 447 | - default: |
|
| 447 | + default: |
|
| 448 | 448 | } |
| 449 | - return $output; |
|
| 449 | + return $output; |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | |
@@ -458,19 +458,19 @@ discard block |
||
| 458 | 458 | * Check that the stats system is configured, report if it isn't |
| 459 | 459 | */ |
| 460 | 460 | function boincstats_check_configuration() { |
| 461 | - $project_id = variable_get('boinc_stats_remote_project_id', ''); |
|
| 462 | - if (!$project_id) { |
|
| 461 | + $project_id = variable_get('boinc_stats_remote_project_id', ''); |
|
| 462 | + if (!$project_id) { |
|
| 463 | 463 | watchdog('boincstats', 'The BOINC stats system is not configured. Please |
| 464 | 464 | !configure_it', array('!configure_it' => l(t('configure it now'), |
| 465 | - 'admin/boinc/stats')), WATCHDOG_ERROR); |
|
| 465 | + 'admin/boinc/stats')), WATCHDOG_ERROR); |
|
| 466 | 466 | if (user_access('administer site configuration')) { |
| 467 | - drupal_set_message(t('The BOINC stats system is not configured. Please |
|
| 467 | + drupal_set_message(t('The BOINC stats system is not configured. Please |
|
| 468 | 468 | !configure_it', array('!configure_it' => l(t('configure it now'), |
| 469 | - 'admin/boinc/stats'))), 'error', FALSE); |
|
| 469 | + 'admin/boinc/stats'))), 'error', FALSE); |
|
| 470 | 470 | } |
| 471 | 471 | else { |
| 472 | - drupal_set_message(t('There is a problem with the site. Please contact |
|
| 472 | + drupal_set_message(t('There is a problem with the site. Please contact |
|
| 473 | 473 | the system administrator.'), 'error', FALSE); |
| 474 | 474 | } |
| 475 | - } |
|
| 475 | + } |
|
| 476 | 476 | } |
@@ -8,38 +8,38 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | - * The BOINC stats configuration determines where statistics are sourced |
|
| 12 | - */ |
|
| 11 | + * The BOINC stats configuration determines where statistics are sourced |
|
| 12 | + */ |
|
| 13 | 13 | function boincstats_admin_stats_system(&$form_state) { |
| 14 | - $form = array(); |
|
| 15 | - $default = array( |
|
| 14 | + $form = array(); |
|
| 15 | + $default = array( |
|
| 16 | 16 | 'boinc_stats_server' => variable_get('boinc_stats_server', 'stats.gridrepublic.org'), |
| 17 | 17 | 'boinc_stats_project_list_rpc' => variable_get('boinc_stats_project_list_rpc', 'rpc/get_projects.php'), |
| 18 | 18 | 'boinc_stats_project_credit_history_rpc' => variable_get('boinc_stats_project_credit_history_rpc', 'rpc2/get_project_tc_history.php'), |
| 19 | 19 | 'boinc_stats_user_credit_history_rpc' => variable_get('boinc_stats_user_credit_history_rpc', 'rpc2/get_user_credit_history.php'), |
| 20 | 20 | 'boinc_stats_remote_project_id' => variable_get('boinc_stats_remote_project_id', ''), |
| 21 | - ); |
|
| 22 | - // Define the form |
|
| 23 | - $form['boinc_stats_server'] = array( |
|
| 21 | + ); |
|
| 22 | + // Define the form |
|
| 23 | + $form['boinc_stats_server'] = array( |
|
| 24 | 24 | '#type' => 'value', |
| 25 | 25 | '#value' => $default['boinc_stats_server'] |
| 26 | - ); |
|
| 27 | - $form['boinc_stats_project_list_rpc'] = array( |
|
| 26 | + ); |
|
| 27 | + $form['boinc_stats_project_list_rpc'] = array( |
|
| 28 | 28 | '#type' => 'value', |
| 29 | 29 | '#value' => $default['boinc_stats_project_list_rpc'] |
| 30 | - ); |
|
| 31 | - $form['boinc_stats_project_credit_history_rpc'] = array( |
|
| 30 | + ); |
|
| 31 | + $form['boinc_stats_project_credit_history_rpc'] = array( |
|
| 32 | 32 | '#type' => 'value', |
| 33 | 33 | '#value' => $default['boinc_stats_project_credit_history_rpc'] |
| 34 | - ); |
|
| 35 | - $form['boinc_stats_user_credit_history_rpc'] = array( |
|
| 34 | + ); |
|
| 35 | + $form['boinc_stats_user_credit_history_rpc'] = array( |
|
| 36 | 36 | '#type' => 'value', |
| 37 | 37 | '#value' => $default['boinc_stats_user_credit_history_rpc'] |
| 38 | - ); |
|
| 39 | - $form['boinc_stats_remote_project_id'] = array( |
|
| 38 | + ); |
|
| 39 | + $form['boinc_stats_remote_project_id'] = array( |
|
| 40 | 40 | '#type' => 'textfield', |
| 41 | 41 | '#title' => t('Stats ID for @project', array( |
| 42 | - '@project' => variable_get('site_name', 'Drupal-BOINC'))), |
|
| 42 | + '@project' => variable_get('site_name', 'Drupal-BOINC'))), |
|
| 43 | 43 | '#default_value' => $default['boinc_stats_remote_project_id'], |
| 44 | 44 | '#description' => t('This project must be registered with a stats system in |
| 45 | 45 | order for some statistics to be available. Currently only one system is |
@@ -47,26 +47,26 @@ discard block |
||
| 47 | 47 | '!find_project_id' => l(t('Find your project ID'), |
| 48 | 48 | "http://{$default['boinc_stats_server']}/{$default['boinc_stats_project_list_rpc']}", |
| 49 | 49 | array('attributes' => array('target' => 'external'))) |
| 50 | - ) |
|
| 50 | + ) |
|
| 51 | 51 | ) |
| 52 | - ); |
|
| 53 | - return system_settings_form($form); |
|
| 52 | + ); |
|
| 53 | + return system_settings_form($form); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | - * Validate the BOINC stats form. |
|
| 58 | - */ |
|
| 57 | + * Validate the BOINC stats form. |
|
| 58 | + */ |
|
| 59 | 59 | function boincstats_admin_stats_system_validate($form, &$form_state) { |
| 60 | - $values = $form_state['values']; |
|
| 61 | - if (!$values['boinc_stats_remote_project_id']) { |
|
| 60 | + $values = $form_state['values']; |
|
| 61 | + if (!$values['boinc_stats_remote_project_id']) { |
|
| 62 | 62 | form_set_error('boinc_stats_remote_project_id', |
| 63 | - t('Stats may not work without a valid stats ID configured!')); |
|
| 64 | - } |
|
| 63 | + t('Stats may not work without a valid stats ID configured!')); |
|
| 64 | + } |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | - * Handle post-validation submission of BOINC stats form. |
|
| 69 | - */ |
|
| 68 | + * Handle post-validation submission of BOINC stats form. |
|
| 69 | + */ |
|
| 70 | 70 | function boincstats_admin_stats_system_submit($form, &$form_state) { |
| 71 | - drupal_set_message(t('Stats system configuration has been updated.')); |
|
| 71 | + drupal_set_message(t('Stats system configuration has been updated.')); |
|
| 72 | 72 | } |
@@ -15,30 +15,30 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | function boinctranslate_initialize_languages() { |
| 17 | 17 | |
| 18 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 18 | + require_once(getcwd() . '/includes/locale.inc'); |
|
| 19 | 19 | |
| 20 | - $api_base_url = 'https://www.transifex.com/api/2'; |
|
| 21 | - $project_name = variable_get( |
|
| 20 | + $api_base_url = 'https://www.transifex.com/api/2'; |
|
| 21 | + $project_name = variable_get( |
|
| 22 | 22 | 'boinc_translate_transifex_project_name', '' |
| 23 | - ); |
|
| 24 | - $operations = array(); |
|
| 23 | + ); |
|
| 24 | + $operations = array(); |
|
| 25 | 25 | |
| 26 | - if ($project_name) { |
|
| 26 | + if ($project_name) { |
|
| 27 | 27 | // Get all languages configured for this project at Transifex |
| 28 | 28 | $path = "project/{$project_name}/languages"; |
| 29 | 29 | $response = boinctranslate_transifex_request($path); |
| 30 | 30 | |
| 31 | 31 | if ($response == '404 NOT FOUND') { |
| 32 | - drupal_set_message( |
|
| 32 | + drupal_set_message( |
|
| 33 | 33 | t('Unable to get languages for %project.', |
| 34 | - array( |
|
| 34 | + array( |
|
| 35 | 35 | '%project' => $project_name, |
| 36 | - ) |
|
| 36 | + ) |
|
| 37 | 37 | ), 'warning' |
| 38 | - ); |
|
| 38 | + ); |
|
| 39 | 39 | } |
| 40 | 40 | elseif ($response) { |
| 41 | - if (is_array($response)) { |
|
| 41 | + if (is_array($response)) { |
|
| 42 | 42 | |
| 43 | 43 | $installed_languages = language_list(); |
| 44 | 44 | $available_languages = _locale_get_predefined_list(); |
@@ -48,13 +48,13 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | // Set up Transifex languages in Drupal |
| 50 | 50 | foreach ($response as $language) { |
| 51 | - $posix_code = $language['language_code']; |
|
| 52 | - $rfc_code = strtolower(str_replace('_', '-', $posix_code)); |
|
| 53 | - $transifex_languages[$rfc_code] = $language; |
|
| 54 | - if (!isset($installed_languages[$rfc_code])) { |
|
| 51 | + $posix_code = $language['language_code']; |
|
| 52 | + $rfc_code = strtolower(str_replace('_', '-', $posix_code)); |
|
| 53 | + $transifex_languages[$rfc_code] = $language; |
|
| 54 | + if (!isset($installed_languages[$rfc_code])) { |
|
| 55 | 55 | // See if this language can be installed from a predefined list |
| 56 | 56 | if (isset($available_languages[$rfc_code])) { |
| 57 | - locale_add_language( |
|
| 57 | + locale_add_language( |
|
| 58 | 58 | $rfc_code, |
| 59 | 59 | NULL, |
| 60 | 60 | NULL, |
@@ -62,30 +62,30 @@ discard block |
||
| 62 | 62 | NULL, |
| 63 | 63 | NULL, |
| 64 | 64 | FALSE |
| 65 | - ); |
|
| 66 | - drupal_set_message( |
|
| 65 | + ); |
|
| 66 | + drupal_set_message( |
|
| 67 | 67 | 'Added predefined language: '.$available_languages[$rfc_code][0] |
| 68 | - ); |
|
| 69 | - db_query("UPDATE {languages} SET enabled = 1 WHERE language = '%s'", $rfc_code); |
|
| 68 | + ); |
|
| 69 | + db_query("UPDATE {languages} SET enabled = 1 WHERE language = '%s'", $rfc_code); |
|
| 70 | 70 | } |
| 71 | 71 | else { |
| 72 | - // Retrieve language details from Transifex |
|
| 73 | - $path = "language/{$posix_code}"; |
|
| 74 | - $response = boinctranslate_transifex_request($path); |
|
| 72 | + // Retrieve language details from Transifex |
|
| 73 | + $path = "language/{$posix_code}"; |
|
| 74 | + $response = boinctranslate_transifex_request($path); |
|
| 75 | 75 | |
| 76 | - if ($response == '404 NOT FOUND') { |
|
| 76 | + if ($response == '404 NOT FOUND') { |
|
| 77 | 77 | drupal_set_message( |
| 78 | - t('Unable to get details for language %code.', |
|
| 78 | + t('Unable to get details for language %code.', |
|
| 79 | 79 | array( |
| 80 | - '%code' => $posix_code, |
|
| 80 | + '%code' => $posix_code, |
|
| 81 | 81 | ) |
| 82 | - ), 'warning' |
|
| 82 | + ), 'warning' |
|
| 83 | 83 | ); |
| 84 | - } |
|
| 85 | - elseif ($response) { |
|
| 84 | + } |
|
| 85 | + elseif ($response) { |
|
| 86 | 86 | if (!empty($response['name'])) { |
| 87 | - // Add a custom language to Drupal and enable |
|
| 88 | - locale_add_language( |
|
| 87 | + // Add a custom language to Drupal and enable |
|
| 88 | + locale_add_language( |
|
| 89 | 89 | $rfc_code, |
| 90 | 90 | $response['name'], |
| 91 | 91 | $response['name'], |
@@ -93,362 +93,362 @@ discard block |
||
| 93 | 93 | NULL, |
| 94 | 94 | NULL, |
| 95 | 95 | TRUE |
| 96 | - ); |
|
| 97 | - drupal_set_message( |
|
| 96 | + ); |
|
| 97 | + drupal_set_message( |
|
| 98 | 98 | 'Added new language: '.$response['name'] |
| 99 | - ); |
|
| 99 | + ); |
|
| 100 | 100 | } |
| 101 | 101 | else { |
| 102 | - $variables = array( |
|
| 102 | + $variables = array( |
|
| 103 | 103 | '%code' => $posix_code, |
| 104 | - ); |
|
| 105 | - drupal_set_message( |
|
| 104 | + ); |
|
| 105 | + drupal_set_message( |
|
| 106 | 106 | t('Unable to get details for language %code.', $variables), |
| 107 | 107 | 'error' |
| 108 | - ); |
|
| 109 | - watchdog( |
|
| 108 | + ); |
|
| 109 | + watchdog( |
|
| 110 | 110 | 'boinctranslate', |
| 111 | 111 | 'Unable to get details for language %code.', |
| 112 | 112 | $variables, |
| 113 | 113 | WATCHDOG_ERROR |
| 114 | - ); |
|
| 114 | + ); |
|
| 115 | + } |
|
| 115 | 116 | } |
| 116 | - } |
|
| 117 | - else { |
|
| 118 | - $variables = array( |
|
| 119 | - '%code' => $posix_code, |
|
| 117 | + else { |
|
| 118 | + $variables = array( |
|
| 119 | + '%code' => $posix_code, |
|
| 120 | 120 | ); |
| 121 | 121 | drupal_set_message( |
| 122 | - t('Invalid response while getting details for language %code.', $variables), |
|
| 123 | - 'error' |
|
| 122 | + t('Invalid response while getting details for language %code.', $variables), |
|
| 123 | + 'error' |
|
| 124 | 124 | ); |
| 125 | 125 | watchdog( |
| 126 | - 'boinctranslate', |
|
| 127 | - 'Invalid response while getting details for language %code.', |
|
| 128 | - $variables, |
|
| 129 | - WATCHDOG_ERROR |
|
| 126 | + 'boinctranslate', |
|
| 127 | + 'Invalid response while getting details for language %code.', |
|
| 128 | + $variables, |
|
| 129 | + WATCHDOG_ERROR |
|
| 130 | 130 | ); |
| 131 | - } |
|
| 131 | + } |
|
| 132 | 132 | } |
| 133 | 133 | // Import any language files for the newly added language |
| 134 | 134 | if ($batch = locale_batch_by_language($rfc_code, '_locale_batch_language_finished')) { |
| 135 | - $operations = array_merge($operations, $batch['operations']); |
|
| 136 | - $process_batches = TRUE; |
|
| 135 | + $operations = array_merge($operations, $batch['operations']); |
|
| 136 | + $process_batches = TRUE; |
|
| 137 | + } |
|
| 137 | 138 | } |
| 138 | - } |
|
| 139 | 139 | } |
| 140 | 140 | drupal_set_message('Finished installing official BOINC languages.'); |
| 141 | 141 | // Disable languages that are not in Transifex |
| 142 | 142 | foreach ($installed_languages as $langcode => $language) { |
| 143 | - if (!isset($transifex_languages[$langcode])) { |
|
| 143 | + if (!isset($transifex_languages[$langcode])) { |
|
| 144 | 144 | $disabled_languages[$langcode] = $langcode; |
| 145 | 145 | db_query("UPDATE {languages} SET enabled = 0 WHERE language = '%s'", $langcode); |
| 146 | - } |
|
| 146 | + } |
|
| 147 | 147 | } |
| 148 | 148 | if ($disabled_languages) { |
| 149 | - drupal_set_message('The following languages were not found in Transifex and were disabled: ' . implode(' ', $disabled_languages)); |
|
| 149 | + drupal_set_message('The following languages were not found in Transifex and were disabled: ' . implode(' ', $disabled_languages)); |
|
| 150 | 150 | } |
| 151 | 151 | if ($process_batches) { |
| 152 | - $batch = array( |
|
| 152 | + $batch = array( |
|
| 153 | 153 | 'operations' => $operations, |
| 154 | - ); |
|
| 155 | - batch_set($batch); |
|
| 156 | - batch_process('admin/boinc/translation'); |
|
| 154 | + ); |
|
| 155 | + batch_set($batch); |
|
| 156 | + batch_process('admin/boinc/translation'); |
|
| 157 | + } |
|
| 157 | 158 | } |
| 158 | - } |
|
| 159 | - else { |
|
| 159 | + else { |
|
| 160 | 160 | $variables = array( |
| 161 | - '%project' => $project_name, |
|
| 161 | + '%project' => $project_name, |
|
| 162 | 162 | ); |
| 163 | 163 | drupal_set_message( |
| 164 | - t('No languages found for %project. (Does the configured account have sufficient privileges at Transifex?)', $variables), |
|
| 165 | - 'error' |
|
| 164 | + t('No languages found for %project. (Does the configured account have sufficient privileges at Transifex?)', $variables), |
|
| 165 | + 'error' |
|
| 166 | 166 | ); |
| 167 | 167 | watchdog( |
| 168 | - 'boinctranslate', |
|
| 169 | - 'No languages found for %project. (Does the configured account have sufficient privileges at Transifex?)', |
|
| 170 | - $variables, |
|
| 171 | - WATCHDOG_ERROR |
|
| 168 | + 'boinctranslate', |
|
| 169 | + 'No languages found for %project. (Does the configured account have sufficient privileges at Transifex?)', |
|
| 170 | + $variables, |
|
| 171 | + WATCHDOG_ERROR |
|
| 172 | 172 | ); |
| 173 | - } |
|
| 173 | + } |
|
| 174 | 174 | } |
| 175 | 175 | else { |
| 176 | - $variables = array( |
|
| 176 | + $variables = array( |
|
| 177 | 177 | '%project' => $project_name, |
| 178 | - ); |
|
| 179 | - drupal_set_message( |
|
| 178 | + ); |
|
| 179 | + drupal_set_message( |
|
| 180 | 180 | t('Invalid response while getting languages for %project.', $variables), |
| 181 | 181 | 'error' |
| 182 | - ); |
|
| 183 | - watchdog( |
|
| 182 | + ); |
|
| 183 | + watchdog( |
|
| 184 | 184 | 'boinctranslate', |
| 185 | 185 | 'Invalid response while getting languages for %project.', |
| 186 | 186 | $variables, |
| 187 | 187 | WATCHDOG_ERROR |
| 188 | - ); |
|
| 188 | + ); |
|
| 189 | 189 | } |
| 190 | - } |
|
| 191 | - drupal_goto('admin/boinc/translation'); |
|
| 190 | + } |
|
| 191 | + drupal_goto('admin/boinc/translation'); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
| 195 | 195 | * |
| 196 | 196 | */ |
| 197 | 197 | function boinctranslate_export_translations() { |
| 198 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 199 | - $project_name = variable_get( |
|
| 198 | + require_once(getcwd() . '/includes/locale.inc'); |
|
| 199 | + $project_name = variable_get( |
|
| 200 | 200 | 'boinc_translate_transifex_project_name', '' |
| 201 | - ); |
|
| 202 | - // Get resource names from local config |
|
| 203 | - $resource_config = (variable_get( |
|
| 201 | + ); |
|
| 202 | + // Get resource names from local config |
|
| 203 | + $resource_config = (variable_get( |
|
| 204 | 204 | 'boinc_translate_transifex_project_resources', '' |
| 205 | - )); |
|
| 206 | - $resource_names = boinctranslate_parse_resources($resource_config); |
|
| 207 | - $primary_resource = reset($resource_names); |
|
| 205 | + )); |
|
| 206 | + $resource_names = boinctranslate_parse_resources($resource_config); |
|
| 207 | + $primary_resource = reset($resource_names); |
|
| 208 | 208 | |
| 209 | - if ($project_name AND $primary_resource) { |
|
| 209 | + if ($project_name AND $primary_resource) { |
|
| 210 | 210 | // Create or update the translation source, if needed |
| 211 | 211 | $source_exists = FALSE; |
| 212 | 212 | $path = "project/{$project_name}/resources"; |
| 213 | 213 | $resources = boinctranslate_transifex_request($path); |
| 214 | 214 | if ($resources AND is_array($resources)) { |
| 215 | - foreach ($resources as $resource) { |
|
| 215 | + foreach ($resources as $resource) { |
|
| 216 | 216 | if ($resource['slug'] == $primary_resource) { |
| 217 | - $source_exists = TRUE; |
|
| 218 | - break; |
|
| 217 | + $source_exists = TRUE; |
|
| 218 | + break; |
|
| 219 | 219 | } |
| 220 | - } |
|
| 221 | - if (!$source_exists) { |
|
| 220 | + } |
|
| 221 | + if (!$source_exists) { |
|
| 222 | 222 | // Create the source |
| 223 | 223 | $path = "project/{$project_name}/resources"; |
| 224 | 224 | $post = array( |
| 225 | - 'slug' => $primary_resource, |
|
| 226 | - 'name' => 'Drupal-Project', |
|
| 227 | - 'i18n_type' => 'PO', |
|
| 228 | - 'category' => 'Drupal', |
|
| 229 | - 'content' => boinctranslate_get_po('en', 'project'), |
|
| 225 | + 'slug' => $primary_resource, |
|
| 226 | + 'name' => 'Drupal-Project', |
|
| 227 | + 'i18n_type' => 'PO', |
|
| 228 | + 'category' => 'Drupal', |
|
| 229 | + 'content' => boinctranslate_get_po('en', 'project'), |
|
| 230 | 230 | ); |
| 231 | 231 | $result = boinctranslate_transifex_request($path, $post); |
| 232 | - } |
|
| 233 | - else { |
|
| 232 | + } |
|
| 233 | + else { |
|
| 234 | 234 | // Update the source |
| 235 | 235 | $path = "project/{$project_name}/resource/{$primary_resource}/content"; |
| 236 | 236 | $post = array( |
| 237 | - 'content' => boinctranslate_get_po('en', 'project') |
|
| 237 | + 'content' => boinctranslate_get_po('en', 'project') |
|
| 238 | 238 | ); |
| 239 | 239 | $result = boinctranslate_transifex_request($path, $post, TRUE, TRUE); |
| 240 | - } |
|
| 240 | + } |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | if (is_array($result) OR substr($result, 0, 6) != 'ERROR:') { |
| 244 | - $enabled_languages = locale_language_list(); |
|
| 245 | - if ($source_exists) { |
|
| 244 | + $enabled_languages = locale_language_list(); |
|
| 245 | + if ($source_exists) { |
|
| 246 | 246 | drupal_set_message('Updated source translation strings at Transifex'); |
| 247 | - } |
|
| 248 | - else { |
|
| 247 | + } |
|
| 248 | + else { |
|
| 249 | 249 | drupal_set_message('Established new translation resource at Transifex'); |
| 250 | - } |
|
| 251 | - // Try to export translations for all enabled languages |
|
| 252 | - foreach ($enabled_languages as $langcode => $language_name) { |
|
| 250 | + } |
|
| 251 | + // Try to export translations for all enabled languages |
|
| 252 | + foreach ($enabled_languages as $langcode => $language_name) { |
|
| 253 | 253 | if ($langcode == 'en') { |
| 254 | - continue; |
|
| 254 | + continue; |
|
| 255 | 255 | } |
| 256 | 256 | $po_file = boinctranslate_get_po($langcode, 'project'); |
| 257 | 257 | if ($po_file) { |
| 258 | - $path = "project/{$project_name}/resource/{$primary_resource}/translation/{$langcode}"; |
|
| 259 | - $post = array( |
|
| 258 | + $path = "project/{$project_name}/resource/{$primary_resource}/translation/{$langcode}"; |
|
| 259 | + $post = array( |
|
| 260 | 260 | 'content' => $po_file, |
| 261 | - ); |
|
| 262 | - $result = boinctranslate_transifex_request($path, $post, TRUE, TRUE); |
|
| 263 | - if (!is_array($result) |
|
| 261 | + ); |
|
| 262 | + $result = boinctranslate_transifex_request($path, $post, TRUE, TRUE); |
|
| 263 | + if (!is_array($result) |
|
| 264 | 264 | AND substr($result, 0, 6) == 'ERROR:') { |
| 265 | 265 | drupal_set_message( |
| 266 | - "Unable to update {$language_name} translations: {$result}", |
|
| 267 | - 'warning' |
|
| 266 | + "Unable to update {$language_name} translations: {$result}", |
|
| 267 | + 'warning' |
|
| 268 | 268 | ); |
| 269 | - } |
|
| 270 | - else { |
|
| 269 | + } |
|
| 270 | + else { |
|
| 271 | 271 | drupal_set_message("Updated {$language_name} translations"); |
| 272 | 272 | //drupal_set_message('DEBUG: <pre>'.print_r($result,1).'</pre>'); |
| 273 | - } |
|
| 273 | + } |
|
| 274 | 274 | } |
| 275 | 275 | else { |
| 276 | - drupal_set_message("No translations to export for {$language_name}"); |
|
| 276 | + drupal_set_message("No translations to export for {$language_name}"); |
|
| 277 | + } |
|
| 277 | 278 | } |
| 278 | - } |
|
| 279 | 279 | } |
| 280 | 280 | else { |
| 281 | - drupal_set_message( |
|
| 281 | + drupal_set_message( |
|
| 282 | 282 | "Unable to update the translation source: {$result}", |
| 283 | 283 | 'warning' |
| 284 | - ); |
|
| 284 | + ); |
|
| 285 | 285 | } |
| 286 | - } |
|
| 287 | - else { |
|
| 286 | + } |
|
| 287 | + else { |
|
| 288 | 288 | drupal_set_message( |
| 289 | - 'Failed to export translations: Transifex settings are not intiailized.', |
|
| 290 | - 'error' |
|
| 289 | + 'Failed to export translations: Transifex settings are not intiailized.', |
|
| 290 | + 'error' |
|
| 291 | 291 | ); |
| 292 | - } |
|
| 293 | - drupal_goto('admin/boinc/translation'); |
|
| 292 | + } |
|
| 293 | + drupal_goto('admin/boinc/translation'); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | /** |
| 297 | 297 | * |
| 298 | 298 | */ |
| 299 | 299 | function boinctranslate_update_official_boinc_translations() { |
| 300 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 301 | - $project_name = variable_get( |
|
| 300 | + require_once(getcwd() . '/includes/locale.inc'); |
|
| 301 | + $project_name = variable_get( |
|
| 302 | 302 | 'boinc_translate_transifex_standard_name', '' |
| 303 | - ); |
|
| 304 | - $drupal_resource = variable_get( |
|
| 303 | + ); |
|
| 304 | + $drupal_resource = variable_get( |
|
| 305 | 305 | 'boinc_translate_transifex_boinc_drupal_resource', '' |
| 306 | - ); |
|
| 306 | + ); |
|
| 307 | 307 | |
| 308 | - if ($project_name AND $drupal_resource) { |
|
| 308 | + if ($project_name AND $drupal_resource) { |
|
| 309 | 309 | // Create or update the translation source, if needed |
| 310 | 310 | $source_exists = FALSE; |
| 311 | 311 | $path = "project/{$project_name}/resources"; |
| 312 | 312 | $resources = boinctranslate_transifex_request($path); |
| 313 | 313 | if ($resources AND is_array($resources)) { |
| 314 | - foreach ($resources as $resource) { |
|
| 314 | + foreach ($resources as $resource) { |
|
| 315 | 315 | if ($resource['slug'] == $drupal_resource) { |
| 316 | - $source_exists = TRUE; |
|
| 317 | - break; |
|
| 316 | + $source_exists = TRUE; |
|
| 317 | + break; |
|
| 318 | + } |
|
| 318 | 319 | } |
| 319 | - } |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | if ($source_exists) { |
| 323 | - $enabled_languages = locale_language_list(); |
|
| 324 | - // Try to export translations for all enabled languages |
|
| 325 | - foreach ($enabled_languages as $langcode => $language_name) { |
|
| 323 | + $enabled_languages = locale_language_list(); |
|
| 324 | + // Try to export translations for all enabled languages |
|
| 325 | + foreach ($enabled_languages as $langcode => $language_name) { |
|
| 326 | 326 | if ($langcode == 'en') { |
| 327 | - continue; |
|
| 327 | + continue; |
|
| 328 | 328 | } |
| 329 | 329 | $po_file = boinctranslate_get_po($langcode, 'boinc'); |
| 330 | 330 | if ($po_file) { |
| 331 | - $path = "project/{$project_name}/resource/{$drupal_resource}/translation/{$langcode}"; |
|
| 332 | - $post = array( |
|
| 331 | + $path = "project/{$project_name}/resource/{$drupal_resource}/translation/{$langcode}"; |
|
| 332 | + $post = array( |
|
| 333 | 333 | 'content' => $po_file, |
| 334 | - ); |
|
| 335 | - $result = boinctranslate_transifex_request($path, $post, TRUE, TRUE); |
|
| 334 | + ); |
|
| 335 | + $result = boinctranslate_transifex_request($path, $post, TRUE, TRUE); |
|
| 336 | 336 | |
| 337 | - if (!is_array($result)) { |
|
| 337 | + if (!is_array($result)) { |
|
| 338 | 338 | if (substr($result, 0, 6) == 'ERROR:') { |
| 339 | - drupal_set_message( |
|
| 339 | + drupal_set_message( |
|
| 340 | 340 | "Unable to update {$language_name} official BOINC translations: {$result}", |
| 341 | 341 | 'warning' |
| 342 | - ); |
|
| 342 | + ); |
|
| 343 | 343 | } |
| 344 | 344 | elseif ($result == '401 UNAUTHORIZED') { |
| 345 | - drupal_set_message( |
|
| 345 | + drupal_set_message( |
|
| 346 | 346 | 'Not authorized to update official BOINC translations', |
| 347 | 347 | 'warning' |
| 348 | - ); |
|
| 349 | - break; |
|
| 348 | + ); |
|
| 349 | + break; |
|
| 350 | 350 | } |
| 351 | 351 | elseif ($result == 'success') { |
| 352 | - drupal_set_message("Updated {$language_name} official BOINC translations"); |
|
| 352 | + drupal_set_message("Updated {$language_name} official BOINC translations"); |
|
| 353 | 353 | } |
| 354 | 354 | else { |
| 355 | - drupal_set_message( |
|
| 355 | + drupal_set_message( |
|
| 356 | 356 | "Unexpected response for {$language_name}: {$result}", |
| 357 | 357 | 'warning' |
| 358 | - ); |
|
| 358 | + ); |
|
| 359 | 359 | } |
| 360 | - } |
|
| 361 | - else { |
|
| 360 | + } |
|
| 361 | + else { |
|
| 362 | 362 | drupal_set_message("Updated {$language_name} official BOINC translations"); |
| 363 | 363 | //drupal_set_message('DEBUG: <pre>'.print_r($result,1).'</pre>'); |
| 364 | - } |
|
| 364 | + } |
|
| 365 | 365 | } |
| 366 | 366 | else { |
| 367 | - drupal_set_message("No official BOINC translations to export for {$language_name}"); |
|
| 367 | + drupal_set_message("No official BOINC translations to export for {$language_name}"); |
|
| 368 | + } |
|
| 368 | 369 | } |
| 369 | - } |
|
| 370 | 370 | } |
| 371 | 371 | else { |
| 372 | - drupal_set_message( |
|
| 372 | + drupal_set_message( |
|
| 373 | 373 | "The {$drupal_resource} resource does not exist in the {$project_name} project at Transifex", |
| 374 | 374 | 'warning' |
| 375 | - ); |
|
| 375 | + ); |
|
| 376 | 376 | } |
| 377 | - } |
|
| 378 | - else { |
|
| 377 | + } |
|
| 378 | + else { |
|
| 379 | 379 | drupal_set_message( |
| 380 | - 'Failed to export official BOINC translations: Transifex settings are not intiailized.', |
|
| 381 | - 'error' |
|
| 380 | + 'Failed to export official BOINC translations: Transifex settings are not intiailized.', |
|
| 381 | + 'error' |
|
| 382 | 382 | ); |
| 383 | - } |
|
| 384 | - drupal_goto('admin/boinc/translation'); |
|
| 383 | + } |
|
| 384 | + drupal_goto('admin/boinc/translation'); |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | /** |
| 388 | 388 | * |
| 389 | 389 | */ |
| 390 | 390 | function boinctranslate_download_pot($type = 'boinc') { |
| 391 | - $po = boinctranslate_get_po(NULL, $type); |
|
| 392 | - _locale_export_po(NULL, $po); |
|
| 391 | + $po = boinctranslate_get_po(NULL, $type); |
|
| 392 | + _locale_export_po(NULL, $po); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | /** |
| 396 | 396 | * |
| 397 | 397 | */ |
| 398 | 398 | function boinctranslate_transifex_request($path, $post = NULL, $json = TRUE, $use_put = FALSE, $username = '', $password = '') { |
| 399 | - $debug_mode = variable_get('boinc_debug_mode', 0); |
|
| 399 | + $debug_mode = variable_get('boinc_debug_mode', 0); |
|
| 400 | 400 | |
| 401 | - // Transifex details |
|
| 402 | - $api_base_url = 'https://www.transifex.com/api/2'; |
|
| 403 | - if (!$username) $username = variable_get('boinc_translate_transifex_user', ''); |
|
| 404 | - if (!$password) $password = variable_get('boinc_translate_transifex_pass', ''); |
|
| 401 | + // Transifex details |
|
| 402 | + $api_base_url = 'https://www.transifex.com/api/2'; |
|
| 403 | + if (!$username) $username = variable_get('boinc_translate_transifex_user', ''); |
|
| 404 | + if (!$password) $password = variable_get('boinc_translate_transifex_pass', ''); |
|
| 405 | 405 | |
| 406 | - $url = "{$api_base_url}/{$path}"; |
|
| 407 | - $headers = array( |
|
| 406 | + $url = "{$api_base_url}/{$path}"; |
|
| 407 | + $headers = array( |
|
| 408 | 408 | 'Authorization' => 'Basic ' . base64_encode($username . ":" . $password), |
| 409 | - ); |
|
| 410 | - $data = NULL; |
|
| 409 | + ); |
|
| 410 | + $data = NULL; |
|
| 411 | 411 | |
| 412 | - if ($post) { |
|
| 412 | + if ($post) { |
|
| 413 | 413 | if ($json) { |
| 414 | - $headers['Content-Type'] = 'application/json'; |
|
| 415 | - $data = json_encode($post); |
|
| 414 | + $headers['Content-Type'] = 'application/json'; |
|
| 415 | + $data = json_encode($post); |
|
| 416 | 416 | } |
| 417 | 417 | else { |
| 418 | - $data = drupal_query_string_encode($post); |
|
| 418 | + $data = drupal_query_string_encode($post); |
|
| 419 | 419 | } |
| 420 | 420 | $method = ($use_put) ? 'PUT' : 'POST'; |
| 421 | - } |
|
| 422 | - else { |
|
| 421 | + } |
|
| 422 | + else { |
|
| 423 | 423 | $method = 'GET'; |
| 424 | - } |
|
| 424 | + } |
|
| 425 | 425 | |
| 426 | - $response = drupal_http_request($url, $headers, $method, $data, 1, 10); |
|
| 426 | + $response = drupal_http_request($url, $headers, $method, $data, 1, 10); |
|
| 427 | 427 | |
| 428 | - switch ($response->code) { |
|
| 429 | - case 200: |
|
| 428 | + switch ($response->code) { |
|
| 429 | + case 200: |
|
| 430 | 430 | case 304: |
| 431 | 431 | if ($json) { |
| 432 | - // Process as JSON |
|
| 433 | - return json_decode($response->data, TRUE); |
|
| 432 | + // Process as JSON |
|
| 433 | + return json_decode($response->data, TRUE); |
|
| 434 | 434 | } |
| 435 | 435 | else { |
| 436 | - return (string) $response->data; |
|
| 436 | + return (string) $response->data; |
|
| 437 | 437 | } |
| 438 | 438 | break; |
| 439 | - case 404: |
|
| 439 | + case 404: |
|
| 440 | 440 | return '404 NOT FOUND'; |
| 441 | - case 401: |
|
| 441 | + case 401: |
|
| 442 | 442 | return '401 UNAUTHORIZED'; |
| 443 | - case 400: |
|
| 443 | + case 400: |
|
| 444 | 444 | if ($debug_mode) watchdog('boinctranslate', "The following response was received when trying to communicate with the Transifex system: \n{$response}", array(), WATCHDOG_WARNING); |
| 445 | 445 | return "ERROR: {$response->data}"; |
| 446 | - case 405: |
|
| 446 | + case 405: |
|
| 447 | 447 | if ($debug_mode) watchdog('boinctranslate', "The following response was received when trying to communicate with the Transifex system: \n{$response}", array(), WATCHDOG_WARNING); |
| 448 | 448 | return "ERROR: User not allowed to perform this action"; |
| 449 | - } |
|
| 449 | + } |
|
| 450 | 450 | |
| 451 | - return NULL; |
|
| 451 | + return NULL; |
|
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | /** |
@@ -456,58 +456,58 @@ discard block |
||
| 456 | 456 | */ |
| 457 | 457 | function boinctranslate_get_po($langcode, $type = 'standard') { |
| 458 | 458 | |
| 459 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 459 | + require_once(getcwd() . '/includes/locale.inc'); |
|
| 460 | 460 | |
| 461 | - $all_languages = language_list(); |
|
| 462 | - $language = $langcode ? $all_languages[$langcode] : NULL; |
|
| 463 | - $textgroups = array(); |
|
| 464 | - $strings = array(); |
|
| 461 | + $all_languages = language_list(); |
|
| 462 | + $language = $langcode ? $all_languages[$langcode] : NULL; |
|
| 463 | + $textgroups = array(); |
|
| 464 | + $strings = array(); |
|
| 465 | 465 | |
| 466 | - switch ($type) { |
|
| 467 | - case 'standard': |
|
| 466 | + switch ($type) { |
|
| 467 | + case 'standard': |
|
| 468 | 468 | $textgroups = array( |
| 469 | - 'default', |
|
| 470 | - 'taxonomy', |
|
| 471 | - 'views', |
|
| 469 | + 'default', |
|
| 470 | + 'taxonomy', |
|
| 471 | + 'views', |
|
| 472 | 472 | ); |
| 473 | 473 | break; |
| 474 | - case 'boinc': |
|
| 474 | + case 'boinc': |
|
| 475 | 475 | $textgroups = array( |
| 476 | - 'boinc', |
|
| 476 | + 'boinc', |
|
| 477 | 477 | ); |
| 478 | 478 | break; |
| 479 | - case 'project': |
|
| 479 | + case 'project': |
|
| 480 | 480 | $textgroups = array( |
| 481 | - 'blocks', |
|
| 482 | - 'menu', |
|
| 483 | - 'project', |
|
| 481 | + 'blocks', |
|
| 482 | + 'menu', |
|
| 483 | + 'project', |
|
| 484 | 484 | ); |
| 485 | 485 | break; |
| 486 | - default: |
|
| 486 | + default: |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | - // Merge textgroup strings together for export as one file |
|
| 490 | - foreach ($textgroups as $textgroup) { |
|
| 489 | + // Merge textgroup strings together for export as one file |
|
| 490 | + foreach ($textgroups as $textgroup) { |
|
| 491 | 491 | $strings += _locale_export_get_strings($language, $textgroup); |
| 492 | - } |
|
| 493 | - ksort($strings); |
|
| 494 | - foreach ($strings as $id => $string) { |
|
| 492 | + } |
|
| 493 | + ksort($strings); |
|
| 494 | + foreach ($strings as $id => $string) { |
|
| 495 | 495 | // Set the string context |
| 496 | 496 | $strings[$id]['context'] = trim($string['comment']); |
| 497 | - } |
|
| 498 | - if ($langcode AND $langcode != 'en') { |
|
| 497 | + } |
|
| 498 | + if ($langcode AND $langcode != 'en') { |
|
| 499 | 499 | // If not the source language, remove untranslated strings from the ouput |
| 500 | 500 | foreach ($strings as $i => $string) { |
| 501 | - if (!$string['translation']) { |
|
| 501 | + if (!$string['translation']) { |
|
| 502 | 502 | unset($strings[$i]); |
| 503 | - } |
|
| 503 | + } |
|
| 504 | 504 | } |
| 505 | - } |
|
| 506 | - if ($strings) { |
|
| 505 | + } |
|
| 506 | + if ($strings) { |
|
| 507 | 507 | return boinctranslate_export_po_generate($language, $strings, NULL, $type); |
| 508 | - } |
|
| 508 | + } |
|
| 509 | 509 | |
| 510 | - return NULL; |
|
| 510 | + return NULL; |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | /** |
@@ -515,21 +515,21 @@ discard block |
||
| 515 | 515 | */ |
| 516 | 516 | function boinctranslate_export_po_generate($language = NULL, $strings = array(), $header = NULL, $type = NULL) { |
| 517 | 517 | |
| 518 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 519 | - global $user; |
|
| 518 | + require_once(getcwd() . '/includes/locale.inc'); |
|
| 519 | + global $user; |
|
| 520 | 520 | |
| 521 | - // unset $language to indicate template creation |
|
| 522 | - if (isset($language) && $language->language == "en") { |
|
| 521 | + // unset $language to indicate template creation |
|
| 522 | + if (isset($language) && $language->language == "en") { |
|
| 523 | 523 | $language = NULL; |
| 524 | - } |
|
| 524 | + } |
|
| 525 | 525 | |
| 526 | - if (!isset($header)) { |
|
| 526 | + if (!isset($header)) { |
|
| 527 | 527 | if (isset($type) && $type == "project") { |
| 528 | - $header = "# ".variable_get('site_name', 'Drupal-BOINC')." drupal localization template\n"; |
|
| 529 | - $header .= "# Copyright (C) ".date("Y")." ".variable_get('site_name', 'Drupal-BOINC')."\n"; |
|
| 528 | + $header = "# ".variable_get('site_name', 'Drupal-BOINC')." drupal localization template\n"; |
|
| 529 | + $header .= "# Copyright (C) ".date("Y")." ".variable_get('site_name', 'Drupal-BOINC')."\n"; |
|
| 530 | 530 | } else { |
| 531 | - $header = "# BOINC drupal localization template\n"; |
|
| 532 | - $header .= "# Copyright (C) ".date("Y")." University of California\n"; |
|
| 531 | + $header = "# BOINC drupal localization template\n"; |
|
| 532 | + $header .= "# Copyright (C) ".date("Y")." University of California\n"; |
|
| 533 | 533 | } |
| 534 | 534 | $header .= '# Generated by ' . $user->name . ' <' . $user->mail . ">\n"; |
| 535 | 535 | $header .= "#\n"; |
@@ -538,201 +538,201 @@ discard block |
||
| 538 | 538 | $header .= "msgid \"\"\n"; |
| 539 | 539 | $header .= "msgstr \"\"\n"; |
| 540 | 540 | if (isset($type) && $type == "project") { |
| 541 | - $header .= "\"Project-Id-Version: ".variable_get('site_name', 'Drupal-BOINC')." ".date("Y-m-d-H:iO")."\\n\"\n"; |
|
| 541 | + $header .= "\"Project-Id-Version: ".variable_get('site_name', 'Drupal-BOINC')." ".date("Y-m-d-H:iO")."\\n\"\n"; |
|
| 542 | 542 | } else { |
| 543 | - $header .= "\"Project-Id-Version: BOINC unknown\\n\"\n"; // TODO: add SHA1 of source checkout here |
|
| 543 | + $header .= "\"Project-Id-Version: BOINC unknown\\n\"\n"; // TODO: add SHA1 of source checkout here |
|
| 544 | 544 | } |
| 545 | 545 | $header .= "\"Report-Msgid-Bugs-To: BOINC translation team <[email protected]>\\n\"\n"; |
| 546 | 546 | $header .= "\"POT-Creation-Date: " . date("Y-m-d H:iO") . "\\n\"\n"; |
| 547 | 547 | if (isset($language)) { |
| 548 | - $header .= "\"PO-Revision-Date: " . date("Y-m-d H:iO") . "\\n\"\n"; |
|
| 548 | + $header .= "\"PO-Revision-Date: " . date("Y-m-d H:iO") . "\\n\"\n"; |
|
| 549 | 549 | } |
| 550 | 550 | $header .= "\"Last-Translator: Generated automatically from Drupal translate interface\\n\"\n"; |
| 551 | 551 | $header .= "\"MIME-Version: 1.0\\n\"\n"; |
| 552 | 552 | $header .= "\"Content-Type: text/plain; charset=utf-8\\n\"\n"; |
| 553 | 553 | $header .= "\"Content-Transfer-Encoding: 8bit\\n\"\n"; |
| 554 | 554 | if (isset($language)) { |
| 555 | - $header .= "\"Language: ".$language->language."\\n\""; |
|
| 556 | - if ($language->formula && $language->plurals) { |
|
| 555 | + $header .= "\"Language: ".$language->language."\\n\""; |
|
| 556 | + if ($language->formula && $language->plurals) { |
|
| 557 | 557 | $header .= "\"Plural-Forms: nplurals=" . $language->plurals . "; plural=" . strtr($language->formula, array('$' => '')) . ";\\n\"\n"; |
| 558 | - } |
|
| 558 | + } |
|
| 559 | 559 | } |
| 560 | 560 | $header .= "\"X-Poedit-SourceCharset: utf-8\\n\"\n"; |
| 561 | - } |
|
| 561 | + } |
|
| 562 | 562 | |
| 563 | - $output = $header . "\n"; |
|
| 563 | + $output = $header . "\n"; |
|
| 564 | 564 | |
| 565 | - foreach ($strings as $lid => $string) { |
|
| 565 | + foreach ($strings as $lid => $string) { |
|
| 566 | 566 | // Only process non-children, children are output below their parent. |
| 567 | 567 | if (!isset($string['child'])) { |
| 568 | - if ($string['comment']) { |
|
| 568 | + if ($string['comment']) { |
|
| 569 | 569 | $output .= '#: ' . $string['comment'] . "\n"; |
| 570 | - } |
|
| 571 | - if ($string['context']) { |
|
| 570 | + } |
|
| 571 | + if ($string['context']) { |
|
| 572 | 572 | $output .= 'msgctxt "' . $string['context'] . "\"\n"; |
| 573 | - } |
|
| 574 | - $output .= 'msgid ' . _locale_export_string($string['source']); |
|
| 575 | - if (!empty($string['plural'])) { |
|
| 573 | + } |
|
| 574 | + $output .= 'msgid ' . _locale_export_string($string['source']); |
|
| 575 | + if (!empty($string['plural'])) { |
|
| 576 | 576 | $plural = $string['plural']; |
| 577 | 577 | $output .= 'msgid_plural ' . _locale_export_string($strings[$plural]['source']); |
| 578 | 578 | if (isset($language)) { |
| 579 | - $translation = $string['translation']; |
|
| 580 | - for ($i = 0; $i < $language->plurals; $i++) { |
|
| 579 | + $translation = $string['translation']; |
|
| 580 | + for ($i = 0; $i < $language->plurals; $i++) { |
|
| 581 | 581 | $output .= 'msgstr[' . $i . '] ' . _locale_export_string($translation); |
| 582 | 582 | if ($plural) { |
| 583 | - $translation = _locale_export_remove_plural($strings[$plural]['translation']); |
|
| 584 | - $plural = isset($strings[$plural]['plural']) ? $strings[$plural]['plural'] : 0; |
|
| 583 | + $translation = _locale_export_remove_plural($strings[$plural]['translation']); |
|
| 584 | + $plural = isset($strings[$plural]['plural']) ? $strings[$plural]['plural'] : 0; |
|
| 585 | 585 | } |
| 586 | 586 | else { |
| 587 | - $translation = ''; |
|
| 587 | + $translation = ''; |
|
| 588 | + } |
|
| 588 | 589 | } |
| 589 | - } |
|
| 590 | 590 | } |
| 591 | 591 | else { |
| 592 | - $output .= 'msgstr[0] ""' . "\n"; |
|
| 593 | - $output .= 'msgstr[1] ""' . "\n"; |
|
| 592 | + $output .= 'msgstr[0] ""' . "\n"; |
|
| 593 | + $output .= 'msgstr[1] ""' . "\n"; |
|
| 594 | + } |
|
| 594 | 595 | } |
| 595 | - } |
|
| 596 | - else { |
|
| 596 | + else { |
|
| 597 | 597 | $output .= 'msgstr ' . _locale_export_string($string['translation']); |
| 598 | - } |
|
| 599 | - $output .= "\n"; |
|
| 598 | + } |
|
| 599 | + $output .= "\n"; |
|
| 600 | 600 | } |
| 601 | - } |
|
| 602 | - return $output; |
|
| 601 | + } |
|
| 602 | + return $output; |
|
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | /** |
| 606 | 606 | * |
| 607 | 607 | */ |
| 608 | 608 | function boinctranslate_refresh_translations() { |
| 609 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 610 | - $errors = array(); |
|
| 611 | - $languages = locale_language_list(); |
|
| 612 | - $translation_resources = array(); |
|
| 613 | - $operations = array(); |
|
| 614 | - $debug_mode = variable_get('boinc_debug_mode', 0); |
|
| 615 | - |
|
| 616 | - $boinc_name = variable_get( |
|
| 609 | + require_once(getcwd() . '/includes/locale.inc'); |
|
| 610 | + $errors = array(); |
|
| 611 | + $languages = locale_language_list(); |
|
| 612 | + $translation_resources = array(); |
|
| 613 | + $operations = array(); |
|
| 614 | + $debug_mode = variable_get('boinc_debug_mode', 0); |
|
| 615 | + |
|
| 616 | + $boinc_name = variable_get( |
|
| 617 | 617 | 'boinc_translate_transifex_standard_name', '' |
| 618 | - ); |
|
| 619 | - $boinc_resources = boinctranslate_parse_resources( |
|
| 618 | + ); |
|
| 619 | + $boinc_resources = boinctranslate_parse_resources( |
|
| 620 | 620 | variable_get('boinc_translate_transifex_standard_resources', array()) |
| 621 | - ); |
|
| 622 | - // Add the Official BOINC resource to the list of BOINC resources; |
|
| 623 | - // The official resource overrides any additional resources provided, so it |
|
| 624 | - // should be added to the end so as to be processed last |
|
| 625 | - $drupal_resource = variable_get( |
|
| 621 | + ); |
|
| 622 | + // Add the Official BOINC resource to the list of BOINC resources; |
|
| 623 | + // The official resource overrides any additional resources provided, so it |
|
| 624 | + // should be added to the end so as to be processed last |
|
| 625 | + $drupal_resource = variable_get( |
|
| 626 | 626 | 'boinc_translate_transifex_boinc_drupal_resource', '' |
| 627 | - ); |
|
| 628 | - $boinc_resources[] = $drupal_resource; |
|
| 629 | - if ($boinc_name AND $boinc_resources) { |
|
| 627 | + ); |
|
| 628 | + $boinc_resources[] = $drupal_resource; |
|
| 629 | + if ($boinc_name AND $boinc_resources) { |
|
| 630 | 630 | $translation_resources[$boinc_name] = array( |
| 631 | - 'resources' => $boinc_resources, |
|
| 632 | - 'textgroups' => array( |
|
| 631 | + 'resources' => $boinc_resources, |
|
| 632 | + 'textgroups' => array( |
|
| 633 | 633 | 'boinc', |
| 634 | 634 | 'default', |
| 635 | 635 | 'taxonomy', |
| 636 | 636 | 'views', |
| 637 | - ), |
|
| 637 | + ), |
|
| 638 | 638 | ); |
| 639 | - } |
|
| 640 | - $project_name = variable_get( |
|
| 639 | + } |
|
| 640 | + $project_name = variable_get( |
|
| 641 | 641 | 'boinc_translate_transifex_project_name', '' |
| 642 | - ); |
|
| 643 | - $project_resources = boinctranslate_parse_resources( |
|
| 642 | + ); |
|
| 643 | + $project_resources = boinctranslate_parse_resources( |
|
| 644 | 644 | variable_get('boinc_translate_transifex_project_resources', array()) |
| 645 | - ); |
|
| 646 | - if ($project_name AND $project_resources) { |
|
| 645 | + ); |
|
| 646 | + if ($project_name AND $project_resources) { |
|
| 647 | 647 | $translation_resources[$project_name] = array( |
| 648 | - 'resources' => $project_resources, |
|
| 649 | - 'textgroups' => array( |
|
| 648 | + 'resources' => $project_resources, |
|
| 649 | + 'textgroups' => array( |
|
| 650 | 650 | 'blocks', |
| 651 | 651 | 'menu', |
| 652 | 652 | 'project', |
| 653 | - ), |
|
| 653 | + ), |
|
| 654 | 654 | ); |
| 655 | 655 | // Be sure any strings from the override file are added to the boinc group |
| 656 | 656 | $override_file = './' . drupal_get_path('module', 'boinctranslate') . '/includes/other-boinc-translation-strings.txt'; |
| 657 | 657 | $other_strings = file($override_file); |
| 658 | 658 | if ($other_strings) { |
| 659 | - foreach ($other_strings as $string) { |
|
| 659 | + foreach ($other_strings as $string) { |
|
| 660 | 660 | $string = trim($string); |
| 661 | 661 | if ($string) { |
| 662 | - // Ignore lines starting with '#' i.e., comments. |
|
| 663 | - if ($string[0] === "#") |
|
| 662 | + // Ignore lines starting with '#' i.e., comments. |
|
| 663 | + if ($string[0] === "#") |
|
| 664 | 664 | continue; |
| 665 | 665 | |
| 666 | - // Use '|' as delimiter to split string and context info. |
|
| 667 | - $line = explode("|", $string); |
|
| 668 | - if ($line) { |
|
| 666 | + // Use '|' as delimiter to split string and context info. |
|
| 667 | + $line = explode("|", $string); |
|
| 668 | + if ($line) { |
|
| 669 | 669 | if (count($line)==1) { |
| 670 | - $tl0 = trim($line[0]); |
|
| 671 | - if ($tl0) { |
|
| 670 | + $tl0 = trim($line[0]); |
|
| 671 | + if ($tl0) { |
|
| 672 | 672 | bts($tl0); |
| 673 | - } |
|
| 673 | + } |
|
| 674 | 674 | } |
| 675 | 675 | elseif (count($line)>1) { |
| 676 | - $tl0 = trim($line[0]); |
|
| 677 | - $tl1 = trim($line[1]); |
|
| 678 | - if ($tl0 and $tl1) { |
|
| 676 | + $tl0 = trim($line[0]); |
|
| 677 | + $tl1 = trim($line[1]); |
|
| 678 | + if ($tl0 and $tl1) { |
|
| 679 | 679 | bts($tl0, array(), NULL, $tl1); |
| 680 | - } |
|
| 680 | + } |
|
| 681 | 681 | } |
| 682 | - }// if ($line) |
|
| 682 | + }// if ($line) |
|
| 683 | 683 | |
| 684 | 684 | }// if ($string) |
| 685 | - }// foreach |
|
| 685 | + }// foreach |
|
| 686 | 686 | }// if ($other_strings) |
| 687 | - } |
|
| 687 | + } |
|
| 688 | 688 | |
| 689 | - foreach ($languages as $langcode => $language) { |
|
| 689 | + foreach ($languages as $langcode => $language) { |
|
| 690 | 690 | if ($langcode == 'en') { |
| 691 | - continue; |
|
| 691 | + continue; |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | $import_stats = array( |
| 695 | - 'new' => 0, |
|
| 696 | - 'updated' => 0, |
|
| 697 | - 'deleted' => 0, |
|
| 698 | - 'skipped' => 0, |
|
| 695 | + 'new' => 0, |
|
| 696 | + 'updated' => 0, |
|
| 697 | + 'deleted' => 0, |
|
| 698 | + 'skipped' => 0, |
|
| 699 | 699 | ); |
| 700 | 700 | |
| 701 | 701 | foreach ($translation_resources as $project => $translation) { |
| 702 | - foreach ($translation['resources'] as $resource) { |
|
| 702 | + foreach ($translation['resources'] as $resource) { |
|
| 703 | 703 | |
| 704 | 704 | // Add this language to the batch operations |
| 705 | 705 | $operations[] = array( |
| 706 | - 'boinctranslate_refresh_translations_op', |
|
| 707 | - array( |
|
| 706 | + 'boinctranslate_refresh_translations_op', |
|
| 707 | + array( |
|
| 708 | 708 | $project, $resource, $langcode, $language, $translation['textgroups'], $debug_mode |
| 709 | - ), |
|
| 709 | + ), |
|
| 710 | 710 | ); |
| 711 | - } |
|
| 711 | + } |
|
| 712 | 712 | } |
| 713 | 713 | if ($batch = locale_batch_by_language($langcode)) { |
| 714 | - foreach ($batch['operations'] as $op) { |
|
| 714 | + foreach ($batch['operations'] as $op) { |
|
| 715 | 715 | $operations[] = array( |
| 716 | - 'boinctranslate_refresh_translations_op', |
|
| 717 | - array( |
|
| 716 | + 'boinctranslate_refresh_translations_op', |
|
| 717 | + array( |
|
| 718 | 718 | NULL, $op[1][0], $langcode, $language, array('default'), $debug_mode |
| 719 | - ), |
|
| 719 | + ), |
|
| 720 | 720 | ); |
| 721 | - } |
|
| 721 | + } |
|
| 722 | + } |
|
| 722 | 723 | } |
| 723 | - } |
|
| 724 | 724 | |
| 725 | - $batch = array( |
|
| 725 | + $batch = array( |
|
| 726 | 726 | 'operations' => $operations, |
| 727 | 727 | 'finished' => 'boinctranslate_refresh_translations_finished', |
| 728 | 728 | 'title' => t('Importing translations'), |
| 729 | 729 | 'init_message' => t('Beginning translation import...'), |
| 730 | 730 | 'progress_message' => t('Applied @current out of @total translation updates.'), |
| 731 | 731 | 'error_message' => t('Translation import has encountered an error.'), |
| 732 | - ); |
|
| 732 | + ); |
|
| 733 | 733 | |
| 734 | - batch_set($batch); |
|
| 735 | - batch_process(); |
|
| 734 | + batch_set($batch); |
|
| 735 | + batch_process(); |
|
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | |
@@ -741,18 +741,18 @@ discard block |
||
| 741 | 741 | */ |
| 742 | 742 | function boinctranslate_refresh_translations_op($project, $resource, $langcode, $language, $textgroups, $debug_mode, &$context) { |
| 743 | 743 | |
| 744 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 744 | + require_once(getcwd() . '/includes/locale.inc'); |
|
| 745 | 745 | |
| 746 | - if ($debug_mode) { |
|
| 746 | + if ($debug_mode) { |
|
| 747 | 747 | watchdog( |
| 748 | - 'boinctranslate', |
|
| 749 | - 'Checking for @language updates in @project:@resource', |
|
| 750 | - array('@language' => $language, '@project' => $project, '@resource' => $resource), |
|
| 751 | - WATCHDOG_INFO |
|
| 748 | + 'boinctranslate', |
|
| 749 | + 'Checking for @language updates in @project:@resource', |
|
| 750 | + array('@language' => $language, '@project' => $project, '@resource' => $resource), |
|
| 751 | + WATCHDOG_INFO |
|
| 752 | 752 | ); |
| 753 | - } |
|
| 753 | + } |
|
| 754 | 754 | |
| 755 | - if ($project) { |
|
| 755 | + if ($project) { |
|
| 756 | 756 | // Import the configured resources |
| 757 | 757 | $success = FALSE; |
| 758 | 758 | $message = ''; |
@@ -760,10 +760,10 @@ discard block |
||
| 760 | 760 | $response = boinctranslate_transifex_request($path); |
| 761 | 761 | |
| 762 | 762 | if ($response == '404 NOT FOUND') { |
| 763 | - $message = "Project resource {$project}:{$resource} not found in {$language}."; |
|
| 763 | + $message = "Project resource {$project}:{$resource} not found in {$language}."; |
|
| 764 | 764 | } |
| 765 | 765 | elseif ($response) { |
| 766 | - if (!empty($response['content'])) { |
|
| 766 | + if (!empty($response['content'])) { |
|
| 767 | 767 | $po_text = $response['content']; |
| 768 | 768 | |
| 769 | 769 | // Write the translation file to a temporary location |
@@ -771,163 +771,163 @@ discard block |
||
| 771 | 771 | $file->filepath = file_save_data($po_text, NULL); |
| 772 | 772 | $file->filename = basename($file->filepath); |
| 773 | 773 | if (!$file->filepath) { |
| 774 | - $message = 'Unable to create temporary file in ' |
|
| 774 | + $message = 'Unable to create temporary file in ' |
|
| 775 | 775 | . file_directory_temp() . " for {$language} translation " |
| 776 | 776 | . "resource {$project}:{$resource}"; |
| 777 | 777 | } |
| 778 | 778 | |
| 779 | 779 | foreach ($textgroups as $textgroup) { |
| 780 | - // Import the translations from the file to each related textgroup |
|
| 781 | - if (!$results = _boinctranslate_locale_import_po($file, $langcode, LOCALE_IMPORT_OVERWRITE, $textgroup)) { |
|
| 780 | + // Import the translations from the file to each related textgroup |
|
| 781 | + if (!$results = _boinctranslate_locale_import_po($file, $langcode, LOCALE_IMPORT_OVERWRITE, $textgroup)) { |
|
| 782 | 782 | $message = "The {$language} translation import of" |
| 783 | - . " {$project}:{$resource} failed."; |
|
| 783 | + . " {$project}:{$resource} failed."; |
|
| 784 | 784 | $success = FALSE; |
| 785 | 785 | break; |
| 786 | - } |
|
| 787 | - else { |
|
| 786 | + } |
|
| 787 | + else { |
|
| 788 | 788 | $success = TRUE; |
| 789 | - } |
|
| 789 | + } |
|
| 790 | + } |
|
| 790 | 791 | } |
| 791 | - } |
|
| 792 | - else { |
|
| 792 | + else { |
|
| 793 | 793 | $message = "Unable to read response for {$language} translation import" |
| 794 | - . " of {$project}:{$resource}."; |
|
| 795 | - } |
|
| 794 | + . " of {$project}:{$resource}."; |
|
| 795 | + } |
|
| 796 | 796 | } |
| 797 | 797 | else { |
| 798 | - $message = "Translation data not found in response for {$language}" |
|
| 798 | + $message = "Translation data not found in response for {$language}" |
|
| 799 | 799 | . " translation import of {$project}:{$resource}."; |
| 800 | 800 | } |
| 801 | - } |
|
| 802 | - else { |
|
| 801 | + } |
|
| 802 | + else { |
|
| 803 | 803 | // If project isn't specified, import as a local Drupal resource |
| 804 | 804 | $project = 'drupal.local'; |
| 805 | 805 | $file = new stdClass(); |
| 806 | 806 | $file->filepath = $resource; |
| 807 | 807 | $file->filename = basename($file->filepath); |
| 808 | 808 | if (!$results = _boinctranslate_locale_import_po($file, $langcode, LOCALE_IMPORT_OVERWRITE, $textgroup)) { |
| 809 | - $message = "The {$language} translation import of" |
|
| 809 | + $message = "The {$language} translation import of" |
|
| 810 | 810 | . " local file {$resource} failed."; |
| 811 | - $success = FALSE; |
|
| 811 | + $success = FALSE; |
|
| 812 | 812 | } |
| 813 | 813 | else { |
| 814 | - $success = TRUE; |
|
| 814 | + $success = TRUE; |
|
| 815 | + } |
|
| 815 | 816 | } |
| 816 | - } |
|
| 817 | 817 | |
| 818 | - if ($success) { |
|
| 818 | + if ($success) { |
|
| 819 | 819 | // Store some result for post-processing in the finished callback. |
| 820 | 820 | $context['results']['success'][] = "{$langcode}:{$textgroup}"; |
| 821 | 821 | $message = "Imported {$language} translations in {$project}:{$resource} ({$results['new']} added, {$results['updated']} refreshed, {$results['deleted']} removed)"; |
| 822 | 822 | |
| 823 | 823 | if ($debug_mode) { |
| 824 | - watchdog( |
|
| 824 | + watchdog( |
|
| 825 | 825 | 'boinctranslate', |
| 826 | 826 | $message, |
| 827 | 827 | array(), |
| 828 | 828 | WATCHDOG_INFO |
| 829 | - ); |
|
| 829 | + ); |
|
| 830 | 830 | } |
| 831 | - } |
|
| 832 | - else { |
|
| 831 | + } |
|
| 832 | + else { |
|
| 833 | 833 | $context['results']['failure'][] = "{$langcode}:{$textgroup}"; |
| 834 | 834 | watchdog( |
| 835 | - 'boinctranslate', |
|
| 836 | - $message, |
|
| 837 | - array(), |
|
| 838 | - WATCHDOG_WARNING |
|
| 835 | + 'boinctranslate', |
|
| 836 | + $message, |
|
| 837 | + array(), |
|
| 838 | + WATCHDOG_WARNING |
|
| 839 | 839 | ); |
| 840 | - } |
|
| 840 | + } |
|
| 841 | 841 | |
| 842 | - // Update our progress information. |
|
| 843 | - $context['sandbox']['progress']++; |
|
| 844 | - $context['sandbox']['language'] = $langcode; |
|
| 845 | - $context['message'] = $message; |
|
| 842 | + // Update our progress information. |
|
| 843 | + $context['sandbox']['progress']++; |
|
| 844 | + $context['sandbox']['language'] = $langcode; |
|
| 845 | + $context['message'] = $message; |
|
| 846 | 846 | |
| 847 | - // Update the progress for the batch engine |
|
| 848 | - if ($context['sandbox']['progress'] >= $context['sandbox']['max']) { |
|
| 847 | + // Update the progress for the batch engine |
|
| 848 | + if ($context['sandbox']['progress'] >= $context['sandbox']['max']) { |
|
| 849 | 849 | $context['finished'] = 1; |
| 850 | - } |
|
| 851 | - else { |
|
| 850 | + } |
|
| 851 | + else { |
|
| 852 | 852 | $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; |
| 853 | - } |
|
| 853 | + } |
|
| 854 | 854 | } |
| 855 | 855 | |
| 856 | 856 | /** |
| 857 | 857 | * Batch 'finished' callback |
| 858 | 858 | */ |
| 859 | 859 | function boinctranslate_refresh_translations_finished($success, $results, $operations) { |
| 860 | - if ($success) { |
|
| 860 | + if ($success) { |
|
| 861 | 861 | // Let's count our successes |
| 862 | 862 | $count = count($results['success']); |
| 863 | 863 | $message = "Successfully completed {$count} import operations"; |
| 864 | 864 | watchdog( |
| 865 | - 'boinctranslate', |
|
| 866 | - 'Successfully completed @count import operations.', |
|
| 867 | - array('@count' => $count), |
|
| 868 | - WATCHDOG_INFO |
|
| 865 | + 'boinctranslate', |
|
| 866 | + 'Successfully completed @count import operations.', |
|
| 867 | + array('@count' => $count), |
|
| 868 | + WATCHDOG_INFO |
|
| 869 | 869 | ); |
| 870 | - } |
|
| 871 | - else { |
|
| 870 | + } |
|
| 871 | + else { |
|
| 872 | 872 | // An error occurred. |
| 873 | 873 | // $operations contains the operations that remained unprocessed. |
| 874 | 874 | $error_operation = reset($operations); |
| 875 | 875 | $message = 'An error occurred while processing ' . $error_operation[0] . ' with arguments :' . print_r($error_operation[0], TRUE); |
| 876 | 876 | watchdog( |
| 877 | - 'boinctranslate', |
|
| 878 | - $message, |
|
| 879 | - array(), |
|
| 880 | - WATCHDOG_WARNING |
|
| 877 | + 'boinctranslate', |
|
| 878 | + $message, |
|
| 879 | + array(), |
|
| 880 | + WATCHDOG_WARNING |
|
| 881 | 881 | ); |
| 882 | - } |
|
| 883 | - drupal_set_message($message); |
|
| 884 | - drupal_goto('admin/boinc/translation'); |
|
| 882 | + } |
|
| 883 | + drupal_set_message($message); |
|
| 884 | + drupal_goto('admin/boinc/translation'); |
|
| 885 | 885 | } |
| 886 | 886 | |
| 887 | 887 | /** |
| 888 | 888 | * |
| 889 | 889 | */ |
| 890 | 890 | function _boinctranslate_locale_import_po($file, $langcode, $mode, $group = NULL) { |
| 891 | - // Try to allocate enough time to parse and import the data. |
|
| 892 | - if (function_exists('set_time_limit')) { |
|
| 891 | + // Try to allocate enough time to parse and import the data. |
|
| 892 | + if (function_exists('set_time_limit')) { |
|
| 893 | 893 | @set_time_limit(240); |
| 894 | - } |
|
| 894 | + } |
|
| 895 | 895 | |
| 896 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 896 | + require_once(getcwd() . '/includes/locale.inc'); |
|
| 897 | 897 | |
| 898 | - // Check if we have the language already in the database. |
|
| 899 | - if (!db_fetch_object(db_query("SELECT language FROM {languages} WHERE language = '%s'", $langcode))) { |
|
| 898 | + // Check if we have the language already in the database. |
|
| 899 | + if (!db_fetch_object(db_query("SELECT language FROM {languages} WHERE language = '%s'", $langcode))) { |
|
| 900 | 900 | drupal_set_message(t('The language selected for import is not supported.'), 'error'); |
| 901 | 901 | return FALSE; |
| 902 | - } |
|
| 902 | + } |
|
| 903 | 903 | |
| 904 | - // Get strings from file (returns on failure after a partial import, or on success) |
|
| 905 | - $status = _boinctranslate_locale_import_read_po('db-store', $file, $mode, $langcode, $group); |
|
| 906 | - if ($status === FALSE) { |
|
| 904 | + // Get strings from file (returns on failure after a partial import, or on success) |
|
| 905 | + $status = _boinctranslate_locale_import_read_po('db-store', $file, $mode, $langcode, $group); |
|
| 906 | + if ($status === FALSE) { |
|
| 907 | 907 | // Error messages are set in _locale_import_read_po(). |
| 908 | 908 | return FALSE; |
| 909 | - } |
|
| 909 | + } |
|
| 910 | 910 | |
| 911 | - // Get status information on import process. |
|
| 912 | - list($headerdone, $additions, $updates, $deletes, $skips) = _boinctranslate_locale_import_one_string('db-report'); |
|
| 911 | + // Get status information on import process. |
|
| 912 | + list($headerdone, $additions, $updates, $deletes, $skips) = _boinctranslate_locale_import_one_string('db-report'); |
|
| 913 | 913 | |
| 914 | - if (!$headerdone) { |
|
| 914 | + if (!$headerdone) { |
|
| 915 | 915 | drupal_set_message(t('The translation file %filename appears to have a missing or malformed header.', array('%filename' => $file->filename)), 'error'); |
| 916 | - } |
|
| 916 | + } |
|
| 917 | 917 | |
| 918 | - // Clear cache and force refresh of JavaScript translations. |
|
| 919 | - _locale_invalidate_js($langcode); |
|
| 920 | - cache_clear_all('locale:', 'cache', TRUE); |
|
| 918 | + // Clear cache and force refresh of JavaScript translations. |
|
| 919 | + _locale_invalidate_js($langcode); |
|
| 920 | + cache_clear_all('locale:', 'cache', TRUE); |
|
| 921 | 921 | |
| 922 | - // Rebuild the menu, strings may have changed. |
|
| 923 | - menu_rebuild(); |
|
| 922 | + // Rebuild the menu, strings may have changed. |
|
| 923 | + menu_rebuild(); |
|
| 924 | 924 | |
| 925 | - return array( |
|
| 925 | + return array( |
|
| 926 | 926 | 'new' => $additions, |
| 927 | 927 | 'updated' => $updates, |
| 928 | 928 | 'deleted' => $deletes, |
| 929 | 929 | 'skipped' => $skips, |
| 930 | - ); |
|
| 930 | + ); |
|
| 931 | 931 | } |
| 932 | 932 | |
| 933 | 933 | /** |
@@ -935,253 +935,253 @@ discard block |
||
| 935 | 935 | */ |
| 936 | 936 | function _boinctranslate_locale_import_read_po($op, $file, $mode = NULL, $lang = NULL, $group = 'default') { |
| 937 | 937 | |
| 938 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 938 | + require_once(getcwd() . '/includes/locale.inc'); |
|
| 939 | 939 | |
| 940 | - $fd = fopen($file->filepath, "rb"); // File will get closed by PHP on return |
|
| 941 | - if (!$fd) { |
|
| 940 | + $fd = fopen($file->filepath, "rb"); // File will get closed by PHP on return |
|
| 941 | + if (!$fd) { |
|
| 942 | 942 | watchdog( |
| 943 | - 'boinctranslate', |
|
| 944 | - 'The translation import for %lang failed, because %filename could not be read.', |
|
| 945 | - array('%lang' => $lang, '%filename' => $file->filename), |
|
| 946 | - WATCHDOG_WARNING |
|
| 943 | + 'boinctranslate', |
|
| 944 | + 'The translation import for %lang failed, because %filename could not be read.', |
|
| 945 | + array('%lang' => $lang, '%filename' => $file->filename), |
|
| 946 | + WATCHDOG_WARNING |
|
| 947 | 947 | ); |
| 948 | 948 | _locale_import_message('The translation import failed, because the file %filename could not be read.', $file); |
| 949 | 949 | return FALSE; |
| 950 | - } |
|
| 950 | + } |
|
| 951 | 951 | |
| 952 | - $context = "COMMENT"; // Parser context: COMMENT, MSGID, MSGID_PLURAL, MSGSTR and MSGSTR_ARR |
|
| 953 | - $current = array(); // Current entry being read |
|
| 954 | - $plural = 0; // Current plural form |
|
| 955 | - $lineno = 0; // Current line |
|
| 952 | + $context = "COMMENT"; // Parser context: COMMENT, MSGID, MSGID_PLURAL, MSGSTR and MSGSTR_ARR |
|
| 953 | + $current = array(); // Current entry being read |
|
| 954 | + $plural = 0; // Current plural form |
|
| 955 | + $lineno = 0; // Current line |
|
| 956 | 956 | |
| 957 | - while (!feof($fd)) { |
|
| 957 | + while (!feof($fd)) { |
|
| 958 | 958 | $line = fgets($fd, 10 * 1024); // A line should not be this long |
| 959 | 959 | if ($lineno == 0) { |
| 960 | - // The first line might come with a UTF-8 BOM, which should be removed. |
|
| 961 | - $line = str_replace("\xEF\xBB\xBF", '', $line); |
|
| 960 | + // The first line might come with a UTF-8 BOM, which should be removed. |
|
| 961 | + $line = str_replace("\xEF\xBB\xBF", '', $line); |
|
| 962 | 962 | } |
| 963 | 963 | $lineno++; |
| 964 | 964 | $line = trim(strtr($line, array("\\\n" => ""))); |
| 965 | 965 | |
| 966 | 966 | if (!strncmp("#", $line, 1)) { // A comment |
| 967 | - if ($context == "COMMENT") { // Already in comment context: add |
|
| 967 | + if ($context == "COMMENT") { // Already in comment context: add |
|
| 968 | 968 | $current["#"][] = substr($line, 1); |
| 969 | - } |
|
| 970 | - elseif (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one |
|
| 969 | + } |
|
| 970 | + elseif (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one |
|
| 971 | 971 | _boinctranslate_locale_import_one_string($op, $current, $mode, $lang, $file, $group); |
| 972 | 972 | $current = array(); |
| 973 | 973 | $current["#"][] = substr($line, 1); |
| 974 | 974 | $context = "COMMENT"; |
| 975 | - } |
|
| 976 | - else { // Parse error |
|
| 975 | + } |
|
| 976 | + else { // Parse error |
|
| 977 | 977 | watchdog( |
| 978 | - 'boinctranslate', |
|
| 979 | - 'The translation file %filename for %lang contains an error: "msgstr" was expected but not found on line %line.', |
|
| 980 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 981 | - WATCHDOG_WARNING |
|
| 978 | + 'boinctranslate', |
|
| 979 | + 'The translation file %filename for %lang contains an error: "msgstr" was expected but not found on line %line.', |
|
| 980 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 981 | + WATCHDOG_WARNING |
|
| 982 | 982 | ); |
| 983 | 983 | _locale_import_message('The translation file %filename contains an error: "msgstr" was expected but not found on line %line.', $file, $lineno); |
| 984 | 984 | return FALSE; |
| 985 | - } |
|
| 985 | + } |
|
| 986 | 986 | } |
| 987 | 987 | elseif (!strncmp("msgctxt", $line, 7)) { |
| 988 | - if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one |
|
| 988 | + if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one |
|
| 989 | 989 | _boinctranslate_locale_import_one_string($op, $current, $mode, $lang, $file, $group); |
| 990 | 990 | $current = array(); |
| 991 | - } |
|
| 992 | - elseif (($context == "MSGID") || ($context == "MSGCTXT")) { // Already in this context? Parse error |
|
| 991 | + } |
|
| 992 | + elseif (($context == "MSGID") || ($context == "MSGCTXT")) { // Already in this context? Parse error |
|
| 993 | 993 | watchdog( |
| 994 | - 'boinctranslate', |
|
| 995 | - 'The translation file %filename for %lang contains an error: "msgctxt" is unexpected on line %line.', |
|
| 996 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 997 | - WATCHDOG_WARNING |
|
| 994 | + 'boinctranslate', |
|
| 995 | + 'The translation file %filename for %lang contains an error: "msgctxt" is unexpected on line %line.', |
|
| 996 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 997 | + WATCHDOG_WARNING |
|
| 998 | 998 | ); |
| 999 | 999 | _locale_import_message('The translation file %filename contains an error: "msgid" is unexpected on line %line.', $file, $lineno); |
| 1000 | 1000 | return FALSE; |
| 1001 | - } |
|
| 1002 | - $line = trim(substr($line, 7)); |
|
| 1003 | - $quoted = _locale_import_parse_quoted($line); |
|
| 1004 | - if ($quoted === FALSE) { |
|
| 1001 | + } |
|
| 1002 | + $line = trim(substr($line, 7)); |
|
| 1003 | + $quoted = _locale_import_parse_quoted($line); |
|
| 1004 | + if ($quoted === FALSE) { |
|
| 1005 | 1005 | watchdog( |
| 1006 | - 'boinctranslate', |
|
| 1007 | - 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1008 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1009 | - WATCHDOG_WARNING |
|
| 1006 | + 'boinctranslate', |
|
| 1007 | + 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1008 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1009 | + WATCHDOG_WARNING |
|
| 1010 | 1010 | ); |
| 1011 | 1011 | _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); |
| 1012 | 1012 | return FALSE; |
| 1013 | - } |
|
| 1014 | - $current["msgctxt"] = $quoted; |
|
| 1015 | - $context = "MSGCTXT"; |
|
| 1013 | + } |
|
| 1014 | + $current["msgctxt"] = $quoted; |
|
| 1015 | + $context = "MSGCTXT"; |
|
| 1016 | 1016 | } |
| 1017 | 1017 | elseif (!strncmp("msgid_plural", $line, 12)) { |
| 1018 | - if ($context != "MSGID") { // Must be plural form for current entry |
|
| 1018 | + if ($context != "MSGID") { // Must be plural form for current entry |
|
| 1019 | 1019 | watchdog( |
| 1020 | - 'boinctranslate', |
|
| 1021 | - 'The translation file %filename for %lang contains an error: "msgid_plural" was expected but not found on line %line.', |
|
| 1022 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1023 | - WATCHDOG_WARNING |
|
| 1020 | + 'boinctranslate', |
|
| 1021 | + 'The translation file %filename for %lang contains an error: "msgid_plural" was expected but not found on line %line.', |
|
| 1022 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1023 | + WATCHDOG_WARNING |
|
| 1024 | 1024 | ); |
| 1025 | 1025 | _locale_import_message('The translation file %filename contains an error: "msgid_plural" was expected but not found on line %line.', $file, $lineno); |
| 1026 | 1026 | return FALSE; |
| 1027 | - } |
|
| 1028 | - $line = trim(substr($line, 12)); |
|
| 1029 | - $quoted = _locale_import_parse_quoted($line); |
|
| 1030 | - if ($quoted === FALSE) { |
|
| 1027 | + } |
|
| 1028 | + $line = trim(substr($line, 12)); |
|
| 1029 | + $quoted = _locale_import_parse_quoted($line); |
|
| 1030 | + if ($quoted === FALSE) { |
|
| 1031 | 1031 | watchdog( |
| 1032 | - 'boinctranslate', |
|
| 1033 | - 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1034 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1035 | - WATCHDOG_WARNING |
|
| 1032 | + 'boinctranslate', |
|
| 1033 | + 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1034 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1035 | + WATCHDOG_WARNING |
|
| 1036 | 1036 | ); |
| 1037 | 1037 | _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); |
| 1038 | 1038 | return FALSE; |
| 1039 | - } |
|
| 1040 | - $current["msgid"] = $current["msgid"] . "\0" . $quoted; |
|
| 1041 | - $context = "MSGID_PLURAL"; |
|
| 1039 | + } |
|
| 1040 | + $current["msgid"] = $current["msgid"] . "\0" . $quoted; |
|
| 1041 | + $context = "MSGID_PLURAL"; |
|
| 1042 | 1042 | } |
| 1043 | 1043 | elseif (!strncmp("msgid", $line, 5)) { |
| 1044 | - if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one |
|
| 1044 | + if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one |
|
| 1045 | 1045 | _boinctranslate_locale_import_one_string($op, $current, $mode, $lang, $file, $group); |
| 1046 | 1046 | $current = array(); |
| 1047 | - } |
|
| 1048 | - elseif ($context == "MSGID") { // Already in this context? Parse error |
|
| 1047 | + } |
|
| 1048 | + elseif ($context == "MSGID") { // Already in this context? Parse error |
|
| 1049 | 1049 | watchdog( |
| 1050 | - 'boinctranslate', |
|
| 1051 | - 'The translation file %filename for %lang contains an error: "msgid" is unexpected on line %line.', |
|
| 1052 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1053 | - WATCHDOG_WARNING |
|
| 1050 | + 'boinctranslate', |
|
| 1051 | + 'The translation file %filename for %lang contains an error: "msgid" is unexpected on line %line.', |
|
| 1052 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1053 | + WATCHDOG_WARNING |
|
| 1054 | 1054 | ); |
| 1055 | 1055 | _locale_import_message('The translation file %filename contains an error: "msgid" is unexpected on line %line.', $file, $lineno); |
| 1056 | 1056 | return FALSE; |
| 1057 | - } |
|
| 1058 | - $line = trim(substr($line, 5)); |
|
| 1059 | - $quoted = _locale_import_parse_quoted($line); |
|
| 1060 | - if ($quoted === FALSE) { |
|
| 1057 | + } |
|
| 1058 | + $line = trim(substr($line, 5)); |
|
| 1059 | + $quoted = _locale_import_parse_quoted($line); |
|
| 1060 | + if ($quoted === FALSE) { |
|
| 1061 | 1061 | watchdog( |
| 1062 | - 'boinctranslate', |
|
| 1063 | - 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1064 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1065 | - WATCHDOG_WARNING |
|
| 1062 | + 'boinctranslate', |
|
| 1063 | + 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1064 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1065 | + WATCHDOG_WARNING |
|
| 1066 | 1066 | ); |
| 1067 | 1067 | _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); |
| 1068 | 1068 | return FALSE; |
| 1069 | - } |
|
| 1070 | - $current["msgid"] = $quoted; |
|
| 1071 | - $context = "MSGID"; |
|
| 1069 | + } |
|
| 1070 | + $current["msgid"] = $quoted; |
|
| 1071 | + $context = "MSGID"; |
|
| 1072 | 1072 | } |
| 1073 | 1073 | elseif (!strncmp("msgstr[", $line, 7)) { |
| 1074 | - if (($context != "MSGID") && ($context != "MSGID_PLURAL") && ($context != "MSGSTR_ARR")) { // Must come after msgid, msgid_plural, or msgstr[] |
|
| 1074 | + if (($context != "MSGID") && ($context != "MSGID_PLURAL") && ($context != "MSGSTR_ARR")) { // Must come after msgid, msgid_plural, or msgstr[] |
|
| 1075 | 1075 | watchdog( |
| 1076 | - 'boinctranslate', |
|
| 1077 | - 'The translation file %filename for %lang contains an error: "msgstr[]" is unexpected on line %line.', |
|
| 1078 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1079 | - WATCHDOG_WARNING |
|
| 1076 | + 'boinctranslate', |
|
| 1077 | + 'The translation file %filename for %lang contains an error: "msgstr[]" is unexpected on line %line.', |
|
| 1078 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1079 | + WATCHDOG_WARNING |
|
| 1080 | 1080 | ); |
| 1081 | 1081 | _locale_import_message('The translation file %filename contains an error: "msgstr[]" is unexpected on line %line.', $file, $lineno); |
| 1082 | 1082 | return FALSE; |
| 1083 | - } |
|
| 1084 | - if (strpos($line, "]") === FALSE) { |
|
| 1083 | + } |
|
| 1084 | + if (strpos($line, "]") === FALSE) { |
|
| 1085 | 1085 | watchdog( |
| 1086 | - 'boinctranslate', |
|
| 1087 | - 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1088 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1089 | - WATCHDOG_WARNING |
|
| 1086 | + 'boinctranslate', |
|
| 1087 | + 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1088 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1089 | + WATCHDOG_WARNING |
|
| 1090 | 1090 | ); |
| 1091 | 1091 | _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); |
| 1092 | 1092 | return FALSE; |
| 1093 | - } |
|
| 1094 | - $frombracket = strstr($line, "["); |
|
| 1095 | - $plural = substr($frombracket, 1, strpos($frombracket, "]") - 1); |
|
| 1096 | - $line = trim(strstr($line, " ")); |
|
| 1097 | - $quoted = _locale_import_parse_quoted($line); |
|
| 1098 | - if ($quoted === FALSE) { |
|
| 1093 | + } |
|
| 1094 | + $frombracket = strstr($line, "["); |
|
| 1095 | + $plural = substr($frombracket, 1, strpos($frombracket, "]") - 1); |
|
| 1096 | + $line = trim(strstr($line, " ")); |
|
| 1097 | + $quoted = _locale_import_parse_quoted($line); |
|
| 1098 | + if ($quoted === FALSE) { |
|
| 1099 | 1099 | watchdog( |
| 1100 | - 'boinctranslate', |
|
| 1101 | - 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1102 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1103 | - WATCHDOG_WARNING |
|
| 1100 | + 'boinctranslate', |
|
| 1101 | + 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1102 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1103 | + WATCHDOG_WARNING |
|
| 1104 | 1104 | ); |
| 1105 | 1105 | _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); |
| 1106 | 1106 | return FALSE; |
| 1107 | - } |
|
| 1108 | - $current["msgstr"][$plural] = $quoted; |
|
| 1109 | - $context = "MSGSTR_ARR"; |
|
| 1107 | + } |
|
| 1108 | + $current["msgstr"][$plural] = $quoted; |
|
| 1109 | + $context = "MSGSTR_ARR"; |
|
| 1110 | 1110 | } |
| 1111 | 1111 | elseif (!strncmp("msgstr", $line, 6)) { |
| 1112 | - if ($context != "MSGID") { // Should come just after a msgid block |
|
| 1112 | + if ($context != "MSGID") { // Should come just after a msgid block |
|
| 1113 | 1113 | watchdog( |
| 1114 | - 'boinctranslate', |
|
| 1115 | - 'The translation file %filename for %lang contains an error: "msgstr" is unexpected on line %line.', |
|
| 1116 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1117 | - WATCHDOG_WARNING |
|
| 1114 | + 'boinctranslate', |
|
| 1115 | + 'The translation file %filename for %lang contains an error: "msgstr" is unexpected on line %line.', |
|
| 1116 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1117 | + WATCHDOG_WARNING |
|
| 1118 | 1118 | ); |
| 1119 | 1119 | _locale_import_message('The translation file %filename contains an error: "msgstr" is unexpected on line %line.', $file, $lineno); |
| 1120 | 1120 | return FALSE; |
| 1121 | - } |
|
| 1122 | - $line = trim(substr($line, 6)); |
|
| 1123 | - $quoted = _locale_import_parse_quoted($line); |
|
| 1124 | - if ($quoted === FALSE) { |
|
| 1121 | + } |
|
| 1122 | + $line = trim(substr($line, 6)); |
|
| 1123 | + $quoted = _locale_import_parse_quoted($line); |
|
| 1124 | + if ($quoted === FALSE) { |
|
| 1125 | 1125 | watchdog( |
| 1126 | - 'boinctranslate', |
|
| 1127 | - 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1128 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1129 | - WATCHDOG_WARNING |
|
| 1126 | + 'boinctranslate', |
|
| 1127 | + 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1128 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1129 | + WATCHDOG_WARNING |
|
| 1130 | 1130 | ); |
| 1131 | 1131 | _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); |
| 1132 | 1132 | return FALSE; |
| 1133 | - } |
|
| 1134 | - $current["msgstr"] = $quoted; |
|
| 1135 | - $context = "MSGSTR"; |
|
| 1133 | + } |
|
| 1134 | + $current["msgstr"] = $quoted; |
|
| 1135 | + $context = "MSGSTR"; |
|
| 1136 | 1136 | } |
| 1137 | 1137 | elseif ($line != "") { |
| 1138 | - $quoted = _locale_import_parse_quoted($line); |
|
| 1139 | - if ($quoted === FALSE) { |
|
| 1138 | + $quoted = _locale_import_parse_quoted($line); |
|
| 1139 | + if ($quoted === FALSE) { |
|
| 1140 | 1140 | watchdog( |
| 1141 | - 'boinctranslate', |
|
| 1142 | - 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1143 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1144 | - WATCHDOG_WARNING |
|
| 1141 | + 'boinctranslate', |
|
| 1142 | + 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1143 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1144 | + WATCHDOG_WARNING |
|
| 1145 | 1145 | ); |
| 1146 | 1146 | _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); |
| 1147 | 1147 | return FALSE; |
| 1148 | - } |
|
| 1149 | - if (($context == "MSGID") || ($context == "MSGID_PLURAL")) { |
|
| 1148 | + } |
|
| 1149 | + if (($context == "MSGID") || ($context == "MSGID_PLURAL")) { |
|
| 1150 | 1150 | $current["msgid"] .= $quoted; |
| 1151 | - } |
|
| 1152 | - elseif ($context == "MSGSTR") { |
|
| 1151 | + } |
|
| 1152 | + elseif ($context == "MSGSTR") { |
|
| 1153 | 1153 | $current["msgstr"] .= $quoted; |
| 1154 | - } |
|
| 1155 | - elseif ($context == "MSGSTR_ARR") { |
|
| 1154 | + } |
|
| 1155 | + elseif ($context == "MSGSTR_ARR") { |
|
| 1156 | 1156 | $current["msgstr"][$plural] .= $quoted; |
| 1157 | - } |
|
| 1158 | - else { |
|
| 1157 | + } |
|
| 1158 | + else { |
|
| 1159 | 1159 | watchdog( |
| 1160 | - 'boinctranslate', |
|
| 1161 | - 'The translation file %filename for %lang contains an error: there is an unexpected string on line %line.', |
|
| 1162 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1163 | - WATCHDOG_WARNING |
|
| 1160 | + 'boinctranslate', |
|
| 1161 | + 'The translation file %filename for %lang contains an error: there is an unexpected string on line %line.', |
|
| 1162 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1163 | + WATCHDOG_WARNING |
|
| 1164 | 1164 | ); |
| 1165 | 1165 | _locale_import_message('The translation file %filename contains an error: there is an unexpected string on line %line.', $file, $lineno); |
| 1166 | 1166 | return FALSE; |
| 1167 | - } |
|
| 1167 | + } |
|
| 1168 | + } |
|
| 1168 | 1169 | } |
| 1169 | - } |
|
| 1170 | 1170 | |
| 1171 | - // End of PO file, flush last entry |
|
| 1172 | - if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { |
|
| 1171 | + // End of PO file, flush last entry |
|
| 1172 | + if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { |
|
| 1173 | 1173 | _boinctranslate_locale_import_one_string($op, $current, $mode, $lang, $file, $group); |
| 1174 | - } |
|
| 1175 | - elseif ($context != "COMMENT") { |
|
| 1174 | + } |
|
| 1175 | + elseif ($context != "COMMENT") { |
|
| 1176 | 1176 | watchdog( |
| 1177 | - 'boinctranslate', |
|
| 1178 | - 'The translation file %filename for %lang ended unexpectedly at line %line.', |
|
| 1179 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1180 | - WATCHDOG_WARNING |
|
| 1177 | + 'boinctranslate', |
|
| 1178 | + 'The translation file %filename for %lang ended unexpectedly at line %line.', |
|
| 1179 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1180 | + WATCHDOG_WARNING |
|
| 1181 | 1181 | ); |
| 1182 | 1182 | _locale_import_message('The translation file %filename ended unexpectedly at line %line.', $file, $lineno); |
| 1183 | 1183 | return FALSE; |
| 1184 | - } |
|
| 1184 | + } |
|
| 1185 | 1185 | |
| 1186 | 1186 | } |
| 1187 | 1187 | |
@@ -1190,28 +1190,28 @@ discard block |
||
| 1190 | 1190 | */ |
| 1191 | 1191 | function _boinctranslate_locale_import_one_string($op, $value = NULL, $mode = NULL, $lang = NULL, $file = NULL, $group = 'default') { |
| 1192 | 1192 | |
| 1193 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 1193 | + require_once(getcwd() . '/includes/locale.inc'); |
|
| 1194 | 1194 | |
| 1195 | - static $report = array( |
|
| 1195 | + static $report = array( |
|
| 1196 | 1196 | 'additions' => 0, |
| 1197 | 1197 | 'updates' => 0, |
| 1198 | 1198 | 'deletes' => 0, |
| 1199 | 1199 | 'skips' => 0, |
| 1200 | - ); |
|
| 1201 | - static $headerdone = FALSE; |
|
| 1202 | - static $strings = array(); |
|
| 1200 | + ); |
|
| 1201 | + static $headerdone = FALSE; |
|
| 1202 | + static $strings = array(); |
|
| 1203 | 1203 | |
| 1204 | - switch ($op) { |
|
| 1204 | + switch ($op) { |
|
| 1205 | 1205 | // Return stored strings |
| 1206 | 1206 | case 'mem-report': |
| 1207 | 1207 | return $strings; |
| 1208 | 1208 | |
| 1209 | - // Store string in memory (only supports single strings) |
|
| 1209 | + // Store string in memory (only supports single strings) |
|
| 1210 | 1210 | case 'mem-store': |
| 1211 | 1211 | $strings[$value['msgid']] = $value['msgstr']; |
| 1212 | - return; |
|
| 1212 | + return; |
|
| 1213 | 1213 | |
| 1214 | - // Called at end of import to inform the user |
|
| 1214 | + // Called at end of import to inform the user |
|
| 1215 | 1215 | case 'db-report': |
| 1216 | 1216 | return array( |
| 1217 | 1217 | $headerdone, |
@@ -1219,57 +1219,57 @@ discard block |
||
| 1219 | 1219 | $report['updates'], |
| 1220 | 1220 | $report['deletes'], |
| 1221 | 1221 | $report['skips'], |
| 1222 | - ); |
|
| 1222 | + ); |
|
| 1223 | 1223 | |
| 1224 | - // Store the string we got in the database. |
|
| 1224 | + // Store the string we got in the database. |
|
| 1225 | 1225 | case 'db-store': |
| 1226 | 1226 | // We got header information. |
| 1227 | 1227 | if ($value['msgid'] == '') { |
| 1228 | 1228 | $languages = language_list(); |
| 1229 | 1229 | if (($mode != LOCALE_IMPORT_KEEP) || empty($languages[$lang]->plurals)) { |
| 1230 | - // Since we only need to parse the header if we ought to update the |
|
| 1231 | - // plural formula, only run this if we don't need to keep existing |
|
| 1232 | - // data untouched or if we don't have an existing plural formula. |
|
| 1233 | - $header = _locale_import_parse_header($value['msgstr']); |
|
| 1230 | + // Since we only need to parse the header if we ought to update the |
|
| 1231 | + // plural formula, only run this if we don't need to keep existing |
|
| 1232 | + // data untouched or if we don't have an existing plural formula. |
|
| 1233 | + $header = _locale_import_parse_header($value['msgstr']); |
|
| 1234 | 1234 | |
| 1235 | - // Get and store the plural formula if available. |
|
| 1236 | - if (isset($header["Plural-Forms"]) && $p = _locale_import_parse_plural_forms($header["Plural-Forms"], $file->filename)) { |
|
| 1235 | + // Get and store the plural formula if available. |
|
| 1236 | + if (isset($header["Plural-Forms"]) && $p = _locale_import_parse_plural_forms($header["Plural-Forms"], $file->filename)) { |
|
| 1237 | 1237 | list($nplurals, $plural) = $p; |
| 1238 | 1238 | db_query("UPDATE {languages} SET plurals = %d, formula = '%s' WHERE language = '%s'", $nplurals, $plural, $lang); |
| 1239 | - } |
|
| 1239 | + } |
|
| 1240 | 1240 | } |
| 1241 | 1241 | $headerdone = TRUE; |
| 1242 | - } |
|
| 1242 | + } |
|
| 1243 | 1243 | |
| 1244 | - else { |
|
| 1244 | + else { |
|
| 1245 | 1245 | // Some real string to import. |
| 1246 | 1246 | $comments = _locale_import_shorten_comments(empty($value['#']) ? array() : $value['#']); |
| 1247 | 1247 | |
| 1248 | 1248 | if (strpos($value['msgid'], "\0")) { |
| 1249 | - // This string has plural versions. |
|
| 1250 | - $english = explode("\0", $value['msgid'], 2); |
|
| 1251 | - $entries = array_keys($value['msgstr']); |
|
| 1252 | - for ($i = 3; $i <= count($entries); $i++) { |
|
| 1249 | + // This string has plural versions. |
|
| 1250 | + $english = explode("\0", $value['msgid'], 2); |
|
| 1251 | + $entries = array_keys($value['msgstr']); |
|
| 1252 | + for ($i = 3; $i <= count($entries); $i++) { |
|
| 1253 | 1253 | $english[] = $english[1]; |
| 1254 | - } |
|
| 1255 | - $translation = array_map('_locale_import_append_plural', $value['msgstr'], $entries); |
|
| 1256 | - $english = array_map('_locale_import_append_plural', $english, $entries); |
|
| 1257 | - foreach ($translation as $key => $trans) { |
|
| 1254 | + } |
|
| 1255 | + $translation = array_map('_locale_import_append_plural', $value['msgstr'], $entries); |
|
| 1256 | + $english = array_map('_locale_import_append_plural', $english, $entries); |
|
| 1257 | + foreach ($translation as $key => $trans) { |
|
| 1258 | 1258 | if ($key == 0) { |
| 1259 | - $plid = 0; |
|
| 1259 | + $plid = 0; |
|
| 1260 | 1260 | } |
| 1261 | 1261 | $plid = _boinctranslate_locale_import_one_string_db($report, $lang, $english[$key], $trans, $group, $comments, $mode, $plid, $key); |
| 1262 | - } |
|
| 1262 | + } |
|
| 1263 | 1263 | } |
| 1264 | 1264 | |
| 1265 | 1265 | else { |
| 1266 | - // A simple string to import. |
|
| 1267 | - $english = $value['msgid']; |
|
| 1268 | - $translation = $value['msgstr']; |
|
| 1269 | - _boinctranslate_locale_import_one_string_db($report, $lang, $english, $translation, $group, $comments, $mode); |
|
| 1266 | + // A simple string to import. |
|
| 1267 | + $english = $value['msgid']; |
|
| 1268 | + $translation = $value['msgstr']; |
|
| 1269 | + _boinctranslate_locale_import_one_string_db($report, $lang, $english, $translation, $group, $comments, $mode); |
|
| 1270 | 1270 | } |
| 1271 | - } |
|
| 1272 | - } // end of db-store operation |
|
| 1271 | + } |
|
| 1272 | + } // end of db-store operation |
|
| 1273 | 1273 | } |
| 1274 | 1274 | |
| 1275 | 1275 | /** |
@@ -1286,15 +1286,15 @@ discard block |
||
| 1286 | 1286 | */ |
| 1287 | 1287 | function _boinctranslate_locale_import_one_string_db(&$report, $langcode, $source, $translation, $textgroup, $location, $mode, $plid = NULL, $plural = NULL) { |
| 1288 | 1288 | |
| 1289 | - $ignoreoverwrite = FALSE; |
|
| 1290 | - $lid = 0; |
|
| 1289 | + $ignoreoverwrite = FALSE; |
|
| 1290 | + $lid = 0; |
|
| 1291 | 1291 | |
| 1292 | - // Use different DB query depending on the textgroup. |
|
| 1293 | - $uselocation = array("boinc", "project"); |
|
| 1294 | - if (in_array($textgroup, $uselocation)) { |
|
| 1292 | + // Use different DB query depending on the textgroup. |
|
| 1293 | + $uselocation = array("boinc", "project"); |
|
| 1294 | + if (in_array($textgroup, $uselocation)) { |
|
| 1295 | 1295 | $resource = db_query("SELECT lid FROM {locales_source} WHERE location = '%s' AND source = '%s' AND textgroup = '%s'", $location, $source, $textgroup); |
| 1296 | - } |
|
| 1297 | - else { |
|
| 1296 | + } |
|
| 1297 | + else { |
|
| 1298 | 1298 | $resource = db_query("SELECT lid FROM {locales_source} WHERE source = '%s' AND textgroup = '%s'", $source, $textgroup); |
| 1299 | 1299 | |
| 1300 | 1300 | // Parse the location string for the string ignoreoverwrite, which |
@@ -1303,61 +1303,61 @@ discard block |
||
| 1303 | 1303 | // location string. |
| 1304 | 1304 | $parts = explode(':', $location); |
| 1305 | 1305 | if (!empty($parts[2])) { |
| 1306 | - if (preg_match('/(ignoreoverwrite)/', $parts[2])) { |
|
| 1306 | + if (preg_match('/(ignoreoverwrite)/', $parts[2])) { |
|
| 1307 | 1307 | $ignoreoverwrite = TRUE; |
| 1308 | - } |
|
| 1308 | + } |
|
| 1309 | 1309 | } |
| 1310 | - }// if (in_array($textgroup, $uselocation)) |
|
| 1310 | + }// if (in_array($textgroup, $uselocation)) |
|
| 1311 | 1311 | |
| 1312 | - if (!empty($translation)) { |
|
| 1312 | + if (!empty($translation)) { |
|
| 1313 | 1313 | // Skip this string unless it passes a check for dangerous code. |
| 1314 | 1314 | // Text groups other than default still can contain HTML tags |
| 1315 | 1315 | // (i.e. translatable blocks). |
| 1316 | 1316 | if ($textgroup == "default" && !locale_string_is_safe($translation)) { |
| 1317 | - $report['skips']++; |
|
| 1318 | - $lid = 0; |
|
| 1317 | + $report['skips']++; |
|
| 1318 | + $lid = 0; |
|
| 1319 | 1319 | } |
| 1320 | 1320 | elseif ($resource) { |
| 1321 | - // We have this source string saved already. Loop over the db results from locales_source table. |
|
| 1322 | - while ($row = db_fetch_array($resource)) { |
|
| 1321 | + // We have this source string saved already. Loop over the db results from locales_source table. |
|
| 1322 | + while ($row = db_fetch_array($resource)) { |
|
| 1323 | 1323 | |
| 1324 | 1324 | $lid = $row['lid']; |
| 1325 | 1325 | // Check of if one or more translations exist for this lid in locales_target table. |
| 1326 | 1326 | $exists = (bool) db_result(db_query("SELECT lid FROM {locales_target} WHERE lid = %d AND language = '%s'", $lid, $langcode)); |
| 1327 | 1327 | if (!$exists) { |
| 1328 | - // No translation in this language, insert translation into locales_target table. |
|
| 1329 | - db_query("INSERT INTO {locales_target} (lid, language, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $langcode, $translation, $plid, $plural); |
|
| 1330 | - $report['additions']++; |
|
| 1328 | + // No translation in this language, insert translation into locales_target table. |
|
| 1329 | + db_query("INSERT INTO {locales_target} (lid, language, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $langcode, $translation, $plid, $plural); |
|
| 1330 | + $report['additions']++; |
|
| 1331 | 1331 | } |
| 1332 | 1332 | else if ( ($mode == LOCALE_IMPORT_OVERWRITE) and (!$ignoreoverwrite) ) { |
| 1333 | - // Translation exists, only overwrite if instructed. |
|
| 1334 | - db_query("UPDATE {locales_target} SET translation = '%s', plid = %d, plural = %d WHERE language = '%s' AND lid = %d", $translation, $plid, $plural, $langcode, $lid); |
|
| 1335 | - $report['updates']++; |
|
| 1333 | + // Translation exists, only overwrite if instructed. |
|
| 1334 | + db_query("UPDATE {locales_target} SET translation = '%s', plid = %d, plural = %d WHERE language = '%s' AND lid = %d", $translation, $plid, $plural, $langcode, $lid); |
|
| 1335 | + $report['updates']++; |
|
| 1336 | 1336 | } |
| 1337 | 1337 | else { |
| 1338 | - $report['skips']++; |
|
| 1338 | + $report['skips']++; |
|
| 1339 | 1339 | }// end if !$exists |
| 1340 | 1340 | |
| 1341 | - }// while |
|
| 1341 | + }// while |
|
| 1342 | 1342 | } |
| 1343 | - } |
|
| 1344 | - elseif ($mode == LOCALE_IMPORT_OVERWRITE AND $resource) { |
|
| 1343 | + } |
|
| 1344 | + elseif ($mode == LOCALE_IMPORT_OVERWRITE AND $resource) { |
|
| 1345 | 1345 | // Loop over db results from locales_source table. |
| 1346 | 1346 | while ($row = db_fetch_array($resource)) { |
| 1347 | - $lid = $row['lid']; |
|
| 1348 | - $exists = (bool) db_result(db_query("SELECT lid FROM {locales_target} WHERE lid = %d AND language = '%s'", $lid, $langcode)); |
|
| 1349 | - if ($exists) { |
|
| 1347 | + $lid = $row['lid']; |
|
| 1348 | + $exists = (bool) db_result(db_query("SELECT lid FROM {locales_target} WHERE lid = %d AND language = '%s'", $lid, $langcode)); |
|
| 1349 | + if ($exists) { |
|
| 1350 | 1350 | // Empty translation, remove existing if instructed. |
| 1351 | 1351 | db_query("DELETE FROM {locales_target} WHERE language = '%s' AND lid = %d AND plid = %d AND plural = %d", $langcode, $lid, $plid, $plural); |
| 1352 | 1352 | $report['deletes']++; |
| 1353 | - }// if $exists |
|
| 1353 | + }// if $exists |
|
| 1354 | 1354 | }// while |
| 1355 | - } |
|
| 1356 | - else { |
|
| 1355 | + } |
|
| 1356 | + else { |
|
| 1357 | 1357 | $report['skips']++; |
| 1358 | - } |
|
| 1358 | + } |
|
| 1359 | 1359 | |
| 1360 | - return $lid; |
|
| 1360 | + return $lid; |
|
| 1361 | 1361 | } |
| 1362 | 1362 | |
| 1363 | 1363 | |
@@ -1366,17 +1366,17 @@ discard block |
||
| 1366 | 1366 | * Parse valid resources out of configuration |
| 1367 | 1367 | */ |
| 1368 | 1368 | function boinctranslate_parse_resources($resource_text) { |
| 1369 | - $resources = array(); |
|
| 1370 | - $resource_array = explode( |
|
| 1369 | + $resources = array(); |
|
| 1370 | + $resource_array = explode( |
|
| 1371 | 1371 | "\n", $resource_text |
| 1372 | - ); |
|
| 1373 | - foreach ($resource_array as $resource) { |
|
| 1372 | + ); |
|
| 1373 | + foreach ($resource_array as $resource) { |
|
| 1374 | 1374 | $resource = trim($resource); |
| 1375 | 1375 | if ($resource AND $resource[0] != '#') { |
| 1376 | - $resources[] = $resource; |
|
| 1376 | + $resources[] = $resource; |
|
| 1377 | 1377 | } |
| 1378 | - } |
|
| 1379 | - return $resources; |
|
| 1378 | + } |
|
| 1379 | + return $resources; |
|
| 1380 | 1380 | } |
| 1381 | 1381 | |
| 1382 | 1382 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * |
@@ -1403,5 +1403,5 @@ discard block |
||
| 1403 | 1403 | * database. |
| 1404 | 1404 | */ |
| 1405 | 1405 | function _boinctranslate_supertrim($instr) { |
| 1406 | - return implode("\n", array_map('trim', preg_split('/\r\n|\r|\n/', $instr) ) ); |
|
| 1406 | + return implode("\n", array_map('trim', preg_split('/\r\n|\r|\n/', $instr) ) ); |
|
| 1407 | 1407 | } |
@@ -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 | |
@@ -7,191 +7,191 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | - * The BOINC community form allows the setting of requirements for interaction |
|
| 11 | - * in the community sections of the site. |
|
| 12 | - */ |
|
| 10 | + * The BOINC community form allows the setting of requirements for interaction |
|
| 11 | + * in the community sections of the site. |
|
| 12 | + */ |
|
| 13 | 13 | function boinccore_admin_community(&$form_state) { |
| 14 | - $form = array(); |
|
| 15 | - $default = array( |
|
| 14 | + $form = array(); |
|
| 15 | + $default = array( |
|
| 16 | 16 | 'min_credit_to_post' => variable_get('boinc_comment_min_credit', 0), |
| 17 | 17 | 'penalty_period' => variable_get('boinc_penalty_period', 7*24*60*60), |
| 18 | 18 | 'moderator_mailing_list' => variable_get('boinc_moderator_mailing_list', ''), |
| 19 | 19 | 'moderator_force_individual_notifications' => variable_get('boinc_moderator_force_individual_notifications', 0), |
| 20 | - ); |
|
| 20 | + ); |
|
| 21 | 21 | |
| 22 | - // Define the form |
|
| 23 | - $form['boinc_comment_min_credit'] = array( |
|
| 22 | + // Define the form |
|
| 23 | + $form['boinc_comment_min_credit'] = array( |
|
| 24 | 24 | '#type' => 'textfield', |
| 25 | 25 | '#title' => t('Credit required for community participation'), |
| 26 | 26 | '#default_value' => $default['min_credit_to_post'], |
| 27 | 27 | '#description' => t('Set a minimum threshold of credit a user must have |
| 28 | 28 | earned before being allowed to create a profile, post comments or participate in forums.'), |
| 29 | - ); |
|
| 30 | - $form['boinc_penalty_period'] = array( |
|
| 29 | + ); |
|
| 30 | + $form['boinc_penalty_period'] = array( |
|
| 31 | 31 | '#type' => 'textfield', |
| 32 | 32 | '#title' => t('Penalty period'), |
| 33 | 33 | '#default_value' => $default['penalty_period'], |
| 34 | 34 | '#description' => t('The amount of time (in seconds) that user privileges |
| 35 | 35 | are revoked when a user is banned from community participation.'), |
| 36 | - ); |
|
| 37 | - $form['boinc_moderator_mailing_list'] = array( |
|
| 36 | + ); |
|
| 37 | + $form['boinc_moderator_mailing_list'] = array( |
|
| 38 | 38 | '#type' => 'textfield', |
| 39 | 39 | '#title' => t('Moderator mailing list'), |
| 40 | 40 | '#default_value' => $default['moderator_mailing_list'], |
| 41 | 41 | '#description' => t('As an alternative to sending moderator notifications |
| 42 | 42 | to individual users with the moderator role, enter a mailing list address |
| 43 | 43 | here to be the only target of the notification emails.'), |
| 44 | - ); |
|
| 45 | - $form['boinc_moderator_force_individual_notifications'] = array( |
|
| 44 | + ); |
|
| 45 | + $form['boinc_moderator_force_individual_notifications'] = array( |
|
| 46 | 46 | '#type' => 'checkbox', |
| 47 | 47 | '#title' => t('Always send individual notifications'), |
| 48 | 48 | '#default_value' => $default['moderator_force_individual_notifications'], |
| 49 | 49 | '#description' => t('Continue to send individual moderator notification |
| 50 | 50 | emails even when a mailing list is provided.'), |
| 51 | - ); |
|
| 51 | + ); |
|
| 52 | 52 | |
| 53 | - $form['tools'] = array( |
|
| 53 | + $form['tools'] = array( |
|
| 54 | 54 | '#title' => t('Tools'), |
| 55 | 55 | '#type' => 'fieldset', |
| 56 | 56 | '#description' => '', |
| 57 | 57 | '#collapsible' => TRUE, |
| 58 | 58 | '#collapsed' => FALSE, |
| 59 | 59 | '#attributes' => array('class' => '') |
| 60 | - ); |
|
| 61 | - $form['tools']['reset_uotd'] = array( |
|
| 60 | + ); |
|
| 61 | + $form['tools']['reset_uotd'] = array( |
|
| 62 | 62 | '#type' => 'submit', |
| 63 | 63 | '#value' => t('Force new UOTD'), |
| 64 | 64 | '#submit' => array('boinccore_reset_user_of_the_day'), |
| 65 | - ); |
|
| 65 | + ); |
|
| 66 | 66 | |
| 67 | - return system_settings_form($form); |
|
| 67 | + return system_settings_form($form); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | - * Validate the BOINC community form. |
|
| 72 | - */ |
|
| 71 | + * Validate the BOINC community form. |
|
| 72 | + */ |
|
| 73 | 73 | function boinccore_admin_community_validate($form, &$form_state) { |
| 74 | - $values = $form_state['values']; |
|
| 75 | - if (!is_numeric($values['boinc_comment_min_credit'])) { |
|
| 74 | + $values = $form_state['values']; |
|
| 75 | + if (!is_numeric($values['boinc_comment_min_credit'])) { |
|
| 76 | 76 | form_set_error('boinc_comment_min_credit', t('The minimum credit value must be a number.')); |
| 77 | - } |
|
| 77 | + } |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
| 81 | - * Handle post-validation submission of BOINC community form. |
|
| 82 | - */ |
|
| 81 | + * Handle post-validation submission of BOINC community form. |
|
| 82 | + */ |
|
| 83 | 83 | function boinccore_admin_community_submit($form, &$form_state) { |
| 84 | - drupal_set_message(t('BOINC community settings have been updated.')); |
|
| 84 | + drupal_set_message(t('BOINC community settings have been updated.')); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | 88 | * Force a reset of the user of the day |
| 89 | 89 | */ |
| 90 | 90 | function boinccore_reset_user_of_the_day() { |
| 91 | - if (boincuser_select_user_of_the_day()) { |
|
| 91 | + if (boincuser_select_user_of_the_day()) { |
|
| 92 | 92 | drupal_set_message(t('The user of the day has been reset.')); |
| 93 | - } |
|
| 93 | + } |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
| 97 | - * The standard page generator form provides an interface to create standard |
|
| 98 | - * pages, such as a Help or About page. |
|
| 99 | - */ |
|
| 97 | + * The standard page generator form provides an interface to create standard |
|
| 98 | + * pages, such as a Help or About page. |
|
| 99 | + */ |
|
| 100 | 100 | function boinccore_admin_default_content(&$form_state) { |
| 101 | - $form = array(); |
|
| 101 | + $form = array(); |
|
| 102 | 102 | |
| 103 | - // Define the form |
|
| 104 | - $form['page'] = array( |
|
| 103 | + // Define the form |
|
| 104 | + $form['page'] = array( |
|
| 105 | 105 | '#type' => 'select', |
| 106 | 106 | '#title' => t('Generate default content for'), |
| 107 | 107 | '#description' => t('Generate some standard pages for a Drupal-BOINC Web site. You may generate all pages or specific pages. If a page already exists, it will <b>not</b> be overwritten. Pages will be generated with the path \'/page\', e.g., \'/help\'. Note the absense of \'content/\'.<p>The pages generated here will have very limited content. Most will have content such as \'Add a link to your FAQ here.\', and it is the admin or editors responsibility to add the necessary content.'), |
| 108 | 108 | '#options' => array( |
| 109 | - 0 => t('All standard pages'), |
|
| 109 | + 0 => t('All standard pages'), |
|
| 110 | 110 | // 'about' => t('About page'), |
| 111 | - 'help' => t('Help page'), |
|
| 112 | - 'rules' => t('Rules and Policies page'), |
|
| 113 | - 'moderation' => t('Moderation information page'), |
|
| 111 | + 'help' => t('Help page'), |
|
| 112 | + 'rules' => t('Rules and Policies page'), |
|
| 113 | + 'moderation' => t('Moderation information page'), |
|
| 114 | 114 | ), |
| 115 | - ); |
|
| 116 | - $form['submit'] = array( |
|
| 115 | + ); |
|
| 116 | + $form['submit'] = array( |
|
| 117 | 117 | '#type' => 'submit', |
| 118 | 118 | '#value' => 'Generate content', |
| 119 | - ); |
|
| 119 | + ); |
|
| 120 | 120 | |
| 121 | - return $form; |
|
| 121 | + return $form; |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | - * Generate content based on the selection made on the form |
|
| 126 | - */ |
|
| 125 | + * Generate content based on the selection made on the form |
|
| 126 | + */ |
|
| 127 | 127 | function boinccore_admin_default_content_submit($form, &$form_state) { |
| 128 | - $option = $form_state['values']['page']; |
|
| 129 | - $page_list = boinccore_admin_default_content_generate($option); |
|
| 130 | - $pages_generated = count($page_list); |
|
| 131 | - if ($pages_generated > 0) { |
|
| 128 | + $option = $form_state['values']['page']; |
|
| 129 | + $page_list = boinccore_admin_default_content_generate($option); |
|
| 130 | + $pages_generated = count($page_list); |
|
| 131 | + if ($pages_generated > 0) { |
|
| 132 | 132 | switch ($pages_generated) { |
| 133 | 133 | case 1: |
| 134 | 134 | $page_list = reset($page_list); |
| 135 | - break; |
|
| 135 | + break; |
|
| 136 | 136 | case 2: |
| 137 | 137 | $page_list = implode(' and ', $page_list); |
| 138 | - break; |
|
| 138 | + break; |
|
| 139 | 139 | default: |
| 140 | 140 | end($page_list); |
| 141 | - $page_list[key($page_list)] = 'and ' . $page_list[key($page_list)]; |
|
| 142 | - $page_list = implode(', ', $page_list); |
|
| 141 | + $page_list[key($page_list)] = 'and ' . $page_list[key($page_list)]; |
|
| 142 | + $page_list = implode(', ', $page_list); |
|
| 143 | 143 | } |
| 144 | 144 | drupal_set_message(t('Default content has been generated for the @listed |
| 145 | 145 | @pages.', array( |
| 146 | 146 | '@listed' => $page_list, |
| 147 | 147 | '@pages' => format_plural($pages_generated, 'page', 'pages'), |
| 148 | - ) |
|
| 148 | + ) |
|
| 149 | 149 | )); |
| 150 | - } |
|
| 151 | - else { |
|
| 150 | + } |
|
| 151 | + else { |
|
| 152 | 152 | if ($option) { |
| 153 | - drupal_set_message(t('The @specified page already exists.', |
|
| 153 | + drupal_set_message(t('The @specified page already exists.', |
|
| 154 | 154 | array('@specified' => $option)), 'warning'); |
| 155 | 155 | } |
| 156 | 156 | else { |
| 157 | - drupal_set_message(t('All pages already exist, so none can be recreated |
|
| 157 | + drupal_set_message(t('All pages already exist, so none can be recreated |
|
| 158 | 158 | automatically.'), 'warning'); |
| 159 | 159 | } |
| 160 | 160 | drupal_set_message(t('To recreate a page, first delete the existing page (or |
| 161 | 161 | remove its URL alias), then try this function again.'), 'warning'); |
| 162 | - } |
|
| 162 | + } |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
| 166 | - * |
|
| 167 | - */ |
|
| 166 | + * |
|
| 167 | + */ |
|
| 168 | 168 | function boinccore_admin_default_content_generate($pages = array()) { |
| 169 | - if (!$pages) { |
|
| 169 | + if (!$pages) { |
|
| 170 | 170 | // If not specified, attempt to generate all pages by default |
| 171 | 171 | $pages = array( |
| 172 | - 'help', |
|
| 172 | + 'help', |
|
| 173 | 173 | // 'about', |
| 174 | - 'rules', |
|
| 175 | - 'moderation', |
|
| 174 | + 'rules', |
|
| 175 | + 'moderation', |
|
| 176 | 176 | ); |
| 177 | - } |
|
| 178 | - elseif (!is_array($pages)) { |
|
| 177 | + } |
|
| 178 | + elseif (!is_array($pages)) { |
|
| 179 | 179 | $pages = array($pages); |
| 180 | - } |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - $pages_generated = array(); |
|
| 183 | - if (in_array('about', $pages)) { |
|
| 182 | + $pages_generated = array(); |
|
| 183 | + if (in_array('about', $pages)) { |
|
| 184 | 184 | // Create the default About page, if it doesn't exist |
| 185 | 185 | // TODO: what is the default About page...? |
| 186 | 186 | if (!drupal_lookup_path('source', 'about')) { |
| 187 | - drupal_set_message('The about page doesn\'t yet have a definition...', 'warning'); |
|
| 188 | - //$pages_generated[] = 'about'; |
|
| 187 | + drupal_set_message('The about page doesn\'t yet have a definition...', 'warning'); |
|
| 188 | + //$pages_generated[] = 'about'; |
|
| 189 | + } |
|
| 189 | 190 | } |
| 190 | - } |
|
| 191 | - if (in_array('help', $pages)) { |
|
| 191 | + if (in_array('help', $pages)) { |
|
| 192 | 192 | // Create the default Help page, if it doesn't exist |
| 193 | 193 | if (!drupal_lookup_path('source', 'help')) { |
| 194 | - $node = array( |
|
| 194 | + $node = array( |
|
| 195 | 195 | 'type' => 'page', |
| 196 | 196 | 'title' => t('Help'), |
| 197 | 197 | 'uid' => 1, |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | 'comment' => 0, // disable comments |
| 205 | 205 | 'moderate' => 0, |
| 206 | 206 | 'body' => preg_replace('/>\s+</', '><', |
| 207 | - '<p>Use this page to provide help and support for your site\'s |
|
| 207 | + '<p>Use this page to provide help and support for your site\'s |
|
| 208 | 208 | visitors:</p> |
| 209 | 209 | <ul> |
| 210 | 210 | <li>Add a link to your primary forum for getting help</li> |
@@ -215,25 +215,25 @@ discard block |
||
| 215 | 215 | 'sticky' => 0, |
| 216 | 216 | 'format' => 4, |
| 217 | 217 | //'teaser' => $teaser, |
| 218 | - ); |
|
| 219 | - $node = (object) $node; // node_save requires an object |
|
| 220 | - node_save($node); |
|
| 218 | + ); |
|
| 219 | + $node = (object) $node; // node_save requires an object |
|
| 220 | + node_save($node); |
|
| 221 | 221 | |
| 222 | - $item = array( |
|
| 222 | + $item = array( |
|
| 223 | 223 | 'link_path' => drupal_get_normal_path('help'), |
| 224 | 224 | 'link_title' => t('Help'), |
| 225 | 225 | 'menu_name' => 'primary-links', |
| 226 | 226 | 'weight' => 50, |
| 227 | - ); |
|
| 228 | - menu_link_save($item); |
|
| 229 | - $pages_generated[] = 'help'; |
|
| 227 | + ); |
|
| 228 | + menu_link_save($item); |
|
| 229 | + $pages_generated[] = 'help'; |
|
| 230 | 230 | } |
| 231 | - } |
|
| 232 | - if (in_array('rules', $pages)) { |
|
| 231 | + } |
|
| 232 | + if (in_array('rules', $pages)) { |
|
| 233 | 233 | // Create the default Rules page, if it doesn't exist |
| 234 | 234 | if (!drupal_lookup_path('source', 'rules-and-policies')) { |
| 235 | - // Create node |
|
| 236 | - $node = array( |
|
| 235 | + // Create node |
|
| 236 | + $node = array( |
|
| 237 | 237 | 'type' => 'page', |
| 238 | 238 | 'title' => t('Rules and Policies'), |
| 239 | 239 | 'uid' => 1, |
@@ -246,30 +246,30 @@ discard block |
||
| 246 | 246 | 'comment' => 0, // disable comments |
| 247 | 247 | 'moderate' => 0, |
| 248 | 248 | 'body' => preg_replace('/>\s+</', '><', |
| 249 | - '<p>Use this page to list your sites rules and policies.</p>'), |
|
| 249 | + '<p>Use this page to list your sites rules and policies.</p>'), |
|
| 250 | 250 | 'sticky' => 0, |
| 251 | 251 | 'format' => 4, |
| 252 | 252 | //'teaser' => $teaser, |
| 253 | - ); |
|
| 254 | - $node = (object) $node; // node_save requires an object |
|
| 255 | - node_save($node); |
|
| 253 | + ); |
|
| 254 | + $node = (object) $node; // node_save requires an object |
|
| 255 | + node_save($node); |
|
| 256 | 256 | |
| 257 | - // Create menu item to node |
|
| 258 | - $item = array( |
|
| 257 | + // Create menu item to node |
|
| 258 | + $item = array( |
|
| 259 | 259 | 'link_path' => drupal_get_normal_path('rules-and-policies'), |
| 260 | 260 | 'link_title' => t('Rules and Policies'), |
| 261 | 261 | 'menu_name' => 'menu-footer-links', |
| 262 | 262 | 'weight' => 0, |
| 263 | - ); |
|
| 264 | - menu_link_save($item); |
|
| 265 | - $pages_generated[] = 'rules-and-policies'; |
|
| 263 | + ); |
|
| 264 | + menu_link_save($item); |
|
| 265 | + $pages_generated[] = 'rules-and-policies'; |
|
| 266 | + } |
|
| 266 | 267 | } |
| 267 | - } |
|
| 268 | - if (in_array('moderation', $pages)) { |
|
| 268 | + if (in_array('moderation', $pages)) { |
|
| 269 | 269 | // Create the default Moderation page, if it doesn't exist |
| 270 | 270 | if (!drupal_lookup_path('source', 'moderation')) { |
| 271 | - // Create node |
|
| 272 | - $node = array( |
|
| 271 | + // Create node |
|
| 272 | + $node = array( |
|
| 273 | 273 | 'type' => 'page', |
| 274 | 274 | 'title' => t('Moderation'), |
| 275 | 275 | 'uid' => 1, |
@@ -282,27 +282,27 @@ discard block |
||
| 282 | 282 | 'comment' => 0, // disable comments |
| 283 | 283 | 'moderate' => 0, |
| 284 | 284 | 'body' => preg_replace('/>\s+</', '><', |
| 285 | - '<p>Use this page to describe your sites moderation policy.</p>'), |
|
| 285 | + '<p>Use this page to describe your sites moderation policy.</p>'), |
|
| 286 | 286 | 'sticky' => 0, |
| 287 | 287 | 'format' => 4, |
| 288 | 288 | //'teaser' => $teaser, |
| 289 | - ); |
|
| 290 | - $node = (object) $node; // node_save requires an object |
|
| 291 | - node_save($node); |
|
| 289 | + ); |
|
| 290 | + $node = (object) $node; // node_save requires an object |
|
| 291 | + node_save($node); |
|
| 292 | 292 | |
| 293 | - // Create menu item to node |
|
| 294 | - $item = array( |
|
| 293 | + // Create menu item to node |
|
| 294 | + $item = array( |
|
| 295 | 295 | 'link_path' => drupal_get_normal_path('moderation'), |
| 296 | 296 | 'link_title' => t('Moderation'), |
| 297 | 297 | 'menu_name' => 'menu-footer-links', |
| 298 | 298 | 'weight' => 0, |
| 299 | - ); |
|
| 300 | - menu_link_save($item); |
|
| 301 | - $pages_generated[] = 'moderation'; |
|
| 299 | + ); |
|
| 300 | + menu_link_save($item); |
|
| 301 | + $pages_generated[] = 'moderation'; |
|
| 302 | + } |
|
| 302 | 303 | } |
| 303 | - } |
|
| 304 | 304 | |
| 305 | - // Rebuild drupal menus |
|
| 306 | - menu_rebuild(); |
|
| 307 | - return $pages_generated; |
|
| 305 | + // Rebuild drupal menus |
|
| 306 | + menu_rebuild(); |
|
| 307 | + return $pages_generated; |
|
| 308 | 308 | } |