/[drupal]/contributions/modules/smfforum/smfforum.module
ViewVC logotype

Contents of /contributions/modules/smfforum/smfforum.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.11 - (show annotations) (download) (as text)
Sat Jun 21 10:05:46 2008 UTC (17 months ago) by vb
Branch: MAIN
CVS Tags: HEAD
Changes since 1.10: +3 -3 lines
File MIME type: text/x-php
bug in 'if ($scrolling =' found by Udi
1 <?php
2 // $Id: smfforum.module,v 1.10 2008/05/31 20:30:53 vb Exp $
3 /**
4 * Copyright 2007-2008 by Vadim G.B. (http://vgb.org.ru)
5 */
6
7 define('SMF_DRUPAL_MODULE', 'SMFforum');
8 define('SMF_MODULE_TAG', 'SMFforum');
9 define('SMF_DRUPAL_MODULE_VERSION', 6);
10
11 define('SMF_API_FILE', '/smf_api_2.php');
12 define('SMF_API_SUBS_FILE', '/smf_api_subs.php');
13 define('SMF_API_INCLUDE_PATH', '/includes');
14 define('SMF_PATH', '/smf');
15 define('SMF_PAGE', 'smfforum');
16
17 define('SMF_SYNC_TO_SMF', 'to SMF');
18 define('SMF_SYNC_TO_DRUPAL', 'to Drupal');
19 define('SMF_SYNC_TO_MASTER', 'to master');
20
21 @define('A_SYNC_TO_UNDEFINED', 0);
22 @define('A_SYNC_TO_ME', 1);
23 @define('A_SYNC_TO_EXTERNAL', 2);
24 @define('A_SYNC_TO_MASTER', 3);
25 @define('A_SYNC_TO_FINISHED', -1);
26
27 define('SMF_NUM_RECENT_POSTS', 10);
28 define('SMF_NUM_RECENT_TOPICS', 10);
29
30 define('SMF_RECENT_DELIMITER_SPACE', " ");
31 define('SMF_RECENT_DELIMITER_BR', "<br />");
32
33 define('SMF_COOKIELENGTH', 1440);
34 define('SMF_NUM_WHOS_ONLINE', 9999);
35 define('SMF_NUM_TOP_POSTERS', 5);
36
37 ////////////////////////////////////////////////////////////////////////////////
38 define('SMF_DISABLE_MODULE', 0); // Only use in emergency
39 define('SMF_DISABLE_AUTO_LOGOUT', 0); // Only use if you are not able to login
40 define('SMF_MODULE_DEBUG', 0); // Do not change!
41 ////////////////////////////////////////////////////////////////////////////////
42
43 global $smf_boarddir, $smf_root_path,
44 $site_base_url, $site_smf_page, $site_forum_url, $smf_integration_mode;
45
46 _smfforum_set_globals();
47
48 function _smfforum_set_globals() {
49 global $smf_config, $base_url, $smf_boarddir, $smf_root_path,
50 $site_base_url, $site_smf_page, $site_forum_url, $smf_integration_mode;
51
52 $site_base_url = $base_url;
53 $site_smf_page = drupal_get_path_alias(SMF_PAGE);
54 $smf_boarddir = $smf_root_path = variable_get('smfforum_root', realpath('.') . SMF_PATH);
55
56 $smf_integration_mode = variable_get("smfforum_page_frame", 0);
57
58 //$smfurl = $smf_config['forum_url'];
59 $site_forum_url = $base_url ."/". $site_smf_page;
60
61 if (module_exists('a_sync')) {
62 variable_set('a_sync_data', 0);
63 variable_set('a_sync_module', '');
64
65 $_a_sync_inc = dirname(__FILE__) .'/smfforum_a_sync.inc';
66 if (file_exists($_a_sync_inc)) {
67 require_once($_a_sync_inc);
68 }
69 }
70
71 /*
72 if (module_exists('services')) {
73 $_smfforum_service_inc = dirname(__FILE__) .'/smfforum_service.inc';
74 if (file_exists($_smfforum_service_inc)) {
75 require_once($_smfforum_service_inc);
76 }
77 }
78 */
79 }
80
81 function _smfforum_get_sync_to($sync) {
82
83 $syncto = $sync;
84 if ($sync == SMF_SYNC_TO_MASTER) {
85 $master = variable_get('smfforum_master', 1);
86 if ($master) {
87 $syncto = SMF_SYNC_TO_DRUPAL;
88 }
89 else {
90 $syncto = SMF_SYNC_TO_SMF;
91 }
92 }
93
94 if (module_exists('a_sync')) {
95 return _smfforum_get_a_sync_to($syncto);
96 }
97
98 return $syncto;
99 }
100
101 function _smfforum_replace_links($output) {
102 global $smf_settings, $base_url;
103
104 $smfurl = $smf_settings['forum_url'];
105 $frameurl = $base_url ."/". drupal_get_path_alias(SMF_PAGE);
106 $output = str_replace($smfurl, $frameurl, $output);
107 // replace back smf images
108 $frameurl = '<img src="'. $frameurl;
109 $smfurl = '<img src="'. $smfurl;
110
111 $output = str_replace($frameurl, $smfurl, $output);
112
113 return $output;
114 }
115
116 function smfforum_whos_online($top_number = SMF_NUM_WHOS_ONLINE, $output_method = '') {
117 global $smf_settings, $smf_user_info, $smf_txt;
118
119 $output = smf_api_whos_online($top_number, $output_method);
120 if (variable_get("smfforum_page_frame", 0) == 1)
121 $output = _smfforum_replace_links($output);
122
123 return $output;
124 }
125
126 function smfforum_recent_posts($num_recent = SMF_NUM_RECENT_POSTS, $exclude_boards = null, $output_tag = "<ul>", $output_br = "<br />", $output_method = '') {
127 global $smf_settings, $smf_user_info, $smf_txt;
128
129 $output = smf_api_recent_posts($num_recent, $exclude_boards, $output_tag, $output_br, $output_method);
130 if (variable_get("smfforum_page_frame", 0) == 1)
131 $output = _smfforum_replace_links($output);
132
133 return $output;
134 }
135
136 function smfforum_recent_topics($num_recent = SMF_NUM_RECENT_TOPICS, $exclude_boards = null, $output_tag = "<ul>", $output_br = "<br />", $output_method = '') {
137 global $smf_settings, $smf_user_info, $smf_txt;
138
139 $output = smf_api_recent_topics($num_recent, $exclude_boards, $output_tag, $output_br, $output_method);
140 if (variable_get("smfforum_page_frame", 0) == 1)
141 $output = _smfforum_replace_links($output);
142
143 return $output;
144 }
145
146 function smfforum_board_stats($output_method = '') {
147 global $smf_settings, $smf_user_info, $smf_txt;
148
149 $output = smf_api_board_stats($output_method);
150 if (variable_get("smfforum_page_frame", 0) == 1)
151 $output = _smfforum_replace_links($output);
152
153 return $output;
154 }
155
156 function smfforum_pm($output_method = '') {
157 global $smf_settings, $smf_user_info, $smf_txt;
158
159 $output = smf_api_pm($output_method);
160 if (variable_get("smfforum_page_frame", 0) == 1)
161 $output = _smfforum_replace_links($output);
162
163 return $output;
164 }
165
166 function smfforum_topposter($top_number = SMF_NUM_TOP_POSTERS, $output_method = '') {
167 global $smf_settings, $smf_user_info, $smf_txt;
168
169 $output = smf_api_topposter($top_number, $output_method);
170 if (variable_get("smfforum_page_frame", 0) == 1)
171 $output = _smfforum_replace_links($output);
172
173 return $output;
174 }
175
176 function _smfforum_settings() {
177 if (SMF_DISABLE_MODULE)
178 return false;
179 $smf_boarddir = variable_get('smfforum_root', '');
180 $smfsettings = $smf_boarddir .'/Settings.php';
181 $smfinc = variable_get('smfforum_inc', '');
182 $smfapifile = variable_get('smfforum_api_file', SMF_API_FILE);
183 $smfapi = $smfinc . $smfapifile;
184 $smfapisubs = $smfinc . SMF_API_SUBS_FILE;
185 if (file_exists($smfapi) && file_exists($smfapisubs) && file_exists($smfsettings)) {
186 require_once($smfapi);
187 return true;
188 }
189 else
190 return false;
191 }
192
193 if (SMF_DRUPAL_MODULE_VERSION == 5) {
194
195 function smfforum_help($section) {
196 $output = '';
197
198 switch ($section) {
199 case 'admin/help#smfforum':
200 break;
201 case 'admin/modules#description':
202 $output .= t('This module provides integration with SMF: Simple Machines Forum.');
203 break;
204 }
205
206 return $output;
207 }
208
209 function smfforum_menu($maycache) {
210 if (variable_get("smfforum_page_frame", 0) == 1) {
211 $items[] = array(
212 'path' => 'smfforum',
213 //'title' => t('SMF Forum'),
214 'access' => user_access('access content'),
215 //'access' => user_access('access forum'),
216 'callback' => 'smfforum_page',
217 'type' => MENU_SUGGESTED_ITEM,
218 //'type' => MENU_NORMAL_ITEM,
219 );
220 }
221 $items[] = array(
222 'path' => 'admin/settings/smfforum',
223 'title' => t('SMFforum settings'),
224 'description' => t('Change SMFforum integration settings'),
225 'callback' => 'drupal_get_form',
226 'callback arguments' => 'smfforum_admin_settings',
227 'access' => user_access('administer site configuration'),
228 'type' => MENU_NORMAL_ITEM,
229 );
230 return $items;
231 }
232
233 function smfforum_admin_settings() { // 5.x
234 // Only administrators can access this page
235 if (!user_access('access administration pages'))
236 return message_access();
237
238 $form = _smfforum_admin_settings();
239 return system_settings_form($form); // 5.x
240 }
241
242 /**
243 * Implementation of hook_form_alter().
244 */
245 function smfforum_form_alter($form_id, &$form) { // 5.x
246 if ($form_id == 'user_login_block' || $form_id == 'user_login') {
247 global $smf_settings;
248 // Get forum URL
249 $scripturl = $smf_settings['forum_url'];
250 $smf_master = variable_get('smfforum_master', 1);
251 if ($smf_master && !empty($scripturl)) {
252 if (variable_get("smfforum_page_frame", 0) == 1) {
253 global $base_url;
254 $scripturl = $base_url ."/". drupal_get_path_alias(SMF_PAGE);
255 }
256 $new_account = $scripturl .'?action=register';
257 $new_password = $scripturl .'?action=reminder';
258
259 $items = array();
260 if (variable_get('user_register', 1)) {
261 $items[] = l(t('Create new account'), $new_account, array('title' => t('Create a new user account.')));
262 }
263 $items[] = l(t('Request new password'), $new_password, array('title' => t('Request new password via e-mail.')));
264 $form['links'] = array('#value' => theme('item_list', $items));
265 }
266 }
267 elseif ($form_id == 'user_register') {
268 }
269 }
270
271 }
272 else { // 6.0
273
274 function smfforum_help($path, $arg) {
275 $output = '';
276 switch ($path) {
277 case 'admin/help#smfforum':
278 break;
279 case 'admin/modules#description':
280 $output .= t('This module provides integration with SMF: Simple Machines Forum.');
281 break;
282 }
283 return $output;
284 }
285
286 /*
287 function smfforum_access($op, $node, $account) {
288
289 if ($op == 'create') {
290 return user_access('create forum topics', $account);
291 }
292
293 if ($op == 'update' || $op == 'delete') {
294 if (user_access('edit own forum topics', $account) && ($account->uid == $node->uid)) {
295 return TRUE;
296 }
297 }
298
299 if ($op == 'view') {
300 return user_access('access content');
301 }
302 }
303
304
305 function smfforum_perm() {
306 return array('view forum', 'administer_forum', 'moderate_forum');
307 }
308 */
309
310 function smfforum_menu() { // 6.0
311
312 $items = array();
313
314 if (variable_get("smfforum_page_frame", 0) == '1') {
315 $items['smfforum'] = array(
316 //'title' => t('SMF Forum'),
317 'page callback' => 'smfforum_page',
318 'access callback' => 'user_access',
319 'access arguments' => array('access content'),
320 'type' => MENU_SUGGESTED_ITEM,
321 //'type' => MENU_NORMAL_ITEM,
322 );
323 }
324
325 $items['admin/settings/smfforum'] = array(
326 'title' => t('SMFforum settings'),
327 'description' => t('Change SMFforum integration settings'),
328 'page callback' => 'drupal_get_form',
329 'page arguments' => array('smfforum_admin_settings'),
330 'access arguments' => array('administer site configuration'),
331 'type' => MENU_NORMAL_ITEM
332 );
333
334 return $items;
335 }
336
337 function smfforum_admin_settings() { // 6.x
338 $form = _smfforum_admin_settings();
339 return system_settings_form($form);
340 }
341
342 /**
343 * Implementation of hook_form_alter().
344 */
345 function smfforum_form_alter(&$form, $form_state, $form_id) { // 6.x
346
347 if ($form_id == 'user_login_block' || $form_id == 'user_login') {
348 $form['#validate'] = smfforum_login_default_validators($form);
349
350 global $smf_settings;
351 // Get forum URL
352 $scripturl = $smf_settings['forum_url'];
353 $smf_master = variable_get('smfforum_master', 1);
354 if ($smf_master && !empty($scripturl)) {
355 if (variable_get("smfforum_page_frame", 0) == 1) {
356 global $base_url;
357 $scripturl = $base_url ."/". drupal_get_path_alias(SMF_PAGE);
358 }
359 $new_account = $scripturl .'?action=register';
360 $new_password = $scripturl .'?action=reminder';
361
362 $items = array();
363 if (variable_get('user_register', 1)) {
364 $items[] = l(t('Create new account'), $new_account, array('title' => t('Create a new user account.')));
365 }
366 $items[] = l(t('Request new password'), $new_password, array('title' => t('Request new password via e-mail.')));
367 $form['links'] = array('#value' => theme('item_list', $items));
368 }
369 }
370 elseif ($form_id == 'user_register') {
371 }
372 return $form;
373 }
374
375 function smfforum_login_default_validators($form) {
376
377 if (module_exists('a_sync')) {
378 $module = a_sync_get_module('validators');
379 if ($module != '') {
380 return $form['#validate'];
381 }
382 $module1 = SMF_PAGE;
383 a_sync_set($module1, 'validators', A_SYNC_TO_FINISHED);
384 }
385
386 $validators = array();
387
388 if (module_exists('logintoboggan')) {
389 if (variable_get('logintoboggan_login_with_email', 0)) {
390 $validators[] = 'logintoboggan_user_login_validate';
391 }
392 }
393
394 $validators[] = 'user_login_name_validate';
395 $validators[] = 'user_login_authenticate_validate';
396 $validators[] = 'smfforum_login_authenticate_validate';
397
398 if (module_exists('a_sync')) {
399 foreach (a_sync_get_modules() as $module) {
400 if ($module != $module1) {
401 $function = $module .'_login_authenticate_validate';
402 if (module_exists($module)) {
403 $validators[] = $function;
404 }
405 }
406 }
407 }
408
409 if (module_exists('ldapauth')) {
410 $validators[] = 'smfforum_ldapauth_login_validate';
411 }
412
413 $validators[] = 'user_login_final_validate';
414 /*
415 if (SMF_MODULE_DEBUG) {
416 drupal_set_message('SMF Form validators');
417 $message = print_r($validators, true);
418 drupal_set_message($message);
419 }
420 */
421 return $validators;
422 }
423
424 /**
425 * A validate handler on the login form. Check supplied username/password
426 * against local users table. If successful, sets the global $user object.
427 */
428 function smfforum_login_authenticate_validate($form, &$form_state) {
429 global $user;
430 if (!$user->uid) {
431 $pass = trim($form_state['values']['pass']);
432 if (!empty($pass)) {
433 smfforum_external_login_register($form_state['values']['name'], $pass);
434 if ($user->uid) {
435 user_authenticate_finalize($form_state['values']);
436 }
437 }
438 }
439 }
440
441 if (module_exists('ldap_integration')) {
442 function smfforum_ldapauth_login_validate($form, &$form_state) {
443 global $user;
444 if (!$user->uid) {
445 $pass = trim($form_state['values']['pass']);
446 if (!empty($pass)) {
447 ldapauth_login_validate($form, $form_state);
448 }
449 }
450 }
451 }
452
453 } // 6
454
455
456
457 function _smfforum_admin_settings() { // 6.x, 5.x
458
459 global $smf_connection, $smf_boarddir, $smf_user_info;
460
461 $form = array();
462 $form['smfstatus'] = array('#type' => 'fieldset',
463 '#title' => t('SMFforum status'),
464 '#collapsible' => TRUE,
465 '#collapsed' => FALSE);
466
467 $smfapi_exists = false;
468 $smfinc = "";
469
470 $smfroot = variable_get('smfforum_root', realpath('.') . SMF_PATH);
471 if (empty($smfroot)) {
472 $smfroot = realpath('.') . SMF_PATH;
473 variable_set('smfforum_root', $smfroot);
474 }
475 $smfsettings = $smfroot .'/Settings.php';
476 $smfapifile = variable_get('smfforum_api_file', SMF_API_FILE);
477 if (empty($smfapifile)) {
478 $smfapifile = SMF_API_FILE;
479 variable_set('smfforum_api_file', $smfapifile);
480 }
481
482 if (file_exists($smfsettings)) {
483 $smfsettings_exists = true;
484 $form['smfstatus']['info3'] = array('#type' => 'markup',
485 '#value' => '<div class="ok">'. t('Successfully locating SMF installation.') .'</div>');
486
487 $smf_boarddir = $smfroot;
488 $smfinc = variable_get('smfforum_inc', drupal_get_path('module', SMF_PAGE) . SMF_API_INCLUDE_PATH);
489 if (empty($smfinc)) {
490 $smfinc = drupal_get_path('module', SMF_PAGE) . SMF_API_INCLUDE_PATH;
491 variable_set('smfforum_inc', $smfinc);
492 }
493 $smfapi = $smfinc . $smfapifile;
494 $smfapisubs = $smfinc . SMF_API_SUBS_FILE;
495 if (file_exists($smfapi) && file_exists($smfapisubs)) {
496 $smfapi_exists = true;
497 }
498 else {
499 $smfapi = $smf_boarddir . $smfapifile;
500 $smfapisubs = $smf_boarddir . SMF_API_SUBS_FILE;
501 if (file_exists($smfapi) && file_exists($smfapisubs)) {
502 $smfapi_exists = true;
503 $smfinc = $smf_boarddir;
504 }
505 }
506 }
507 else {
508 $smfsettings_exists = false;
509 $form['smfstatus']['info4'] = array('#type' => 'markup',
510 '#value' => '<div class="error">'. t('Error locating SMF installation.') .' '. t('Please fix your settings!') .'</div>');
511 }
512
513 if ($smfapi_exists) {
514 $form['smfstatus']['info1'] = array('#type' => 'markup',
515 '#value' => '<div class="ok">'. t('Successfully locating %api.', array('%api' => $smfapi)) .'</div>');
516 }
517 else {
518 $form['smfstatus']['info2'] = array('#type' => 'markup',
519 '#value' => '<div class="error">'. t('Error locating %api.', array('%api' => $smfapi)) .' '. t('Please fix your settings!') .'</div>');
520 }
521 /*
522 if (SMF_MODULE_DEBUG) {
523 global $active_db;
524 $message = '0 D = SMF '.$active_db.' == '.$smf_connection;
525 drupal_set_message($message);
526 }
527 */
528 if ($smfsettings_exists && $smfapi_exists)
529 require_once($smfapi);
530 /*
531 if (SMF_MODULE_DEBUG) {
532 $message = '1 D = SMF '.$active_db.' == '.$smf_connection;
533 drupal_set_message($message);
534 }
535 */
536 if ($smf_connection) {
537 $form['smfstatus']['info5'] = array('#type' => 'markup',
538 '#value' => '<div class="ok">'. t('Successfully connected to the SMF database.') .'</div>');
539 }
540 else {
541 $form['smfstatus']['info6'] = array('#type' => 'markup',
542 '#value' => '<div class="error">'. t('Unable to connect to the SMF database.') .' '. t('Please fix your settings!') .'</div>');
543 }
544
545 $form['smfsettings'] = array('#type' => 'fieldset',
546 '#title' => t('SMF location settings'),
547 '#collapsible' => TRUE,
548 '#collapsed' => FALSE);
549
550 $form['smfsettings']['smfforum_root'] = array('#type' => 'textfield',
551 '#title' => t('SMFforum root'),
552 '#maxlength' => '128', '#size' => '60',
553 '#default_value' => $smfroot,
554 '#description' => t('Path to forum directory. Enter the full directory path where SMF is installed.'));
555
556 if ($smfsettings_exists) {
557 $form['smfsettings']['smfforum_inc'] = array('#type' => 'textfield',
558 '#title' => t('Path to SMF api file'),
559 '#maxlength' => '128', '#size' => '60',
560 '#default_value' => $smfinc,
561 '#description' => t('Enter the full directory path where SMF api file is located.'));
562
563 $form['smfsettings']['smfforum_api_file'] = array('#type' => 'textfield',
564 '#title' => t('SMF api file name'),
565 '#maxlength' => '128', '#size' => '60',
566 '#default_value' => $smfapifile,
567 '#description' => t('Enter SMF api file name.'));
568 }
569
570 if ($smf_connection) {
571
572 $form['drupalsettings'] = array('#type' => 'fieldset',
573 '#title' => t('SMF/Drupal settings'),
574 '#collapsible' => TRUE,
575 '#collapsed' => FALSE);
576
577 $qookie_test = variable_get('smfforum_qookie_test', 0);
578
579 $authenticated = smf_api_authenticate_user();
580
581 if ($authenticated) {
582 $form['smfstatus']['info7'] = array('#type' => 'markup',
583 '#value' => '<div class="ok">'. t('Successfully authenticated SMF user: %name.', array('%name' => smf_api_utf8($smf_user_info['name']))) .'</div>');
584 $qookie_test = 1;
585 variable_set('smfforum_qookie_test', $qookie_test);
586 }
587 else {
588 if ($qookie_test == 0 || $qookie_test == 2) {
589 $form['smfstatus']['info8'] = array('#type' => 'markup',
590 '#value' => '<div class="error">'. t('You are not authenticated in SMF now.') .' '. t('Please login to SMF and test again. You may refresh settings!') .'</div>');
591 $qookie_test = 0;
592 }
593 else {
594 $form['smfstatus']['info8'] = array('#type' => 'markup',
595 '#value' => '<div class="ok">'. t('You are not authenticated in SMF now.') .'</div>');
596 }
597 }
598
599 $form['drupalsettings']['smfforum_qookie_test'] = array(
600 '#type' => 'radios',
601 '#title' => t('SMF qookie authentication test'),
602 '#default_value' => $qookie_test,
603 '#options' => array(0 => t('Not passed'), 1 => t('Passed'), 2 => t('Test')),
604 );
605
606 $form['drupalsettings']['smfforum_master'] = array(
607 '#type' => 'radios',
608 '#title' => t('Select master registration system'),
609 '#default_value' => variable_get('smfforum_master', 1),
610 '#options' => array(0 => t('Drupal master'), 1 => t('SMF master')),
611 );
612
613 $form['drupalsettings']['smfforum_cookie_length'] = array('#type' => 'textfield',
614 '#title' => t('Session length'),
615 '#maxlength' => '6', '#size' => '6',
616 '#default_value' => variable_get('smfforum_cookie_length', SMF_COOKIELENGTH),
617 '#description' => t('Enter the session length in minutes to stay logged in.'));
618
619 $form['drupalsettings']['smfforum_num_whos_online'] = array('#type' => 'textfield',
620 '#title' => t('Number of online forum users'),
621 '#maxlength' => '4', '#size' => '4',
622 '#default_value' => variable_get('smfforum_num_whos_online', SMF_NUM_WHOS_ONLINE),
623 '#description' => t('Enter the number of online forum users.'));
624
625 $form['drupalsettings']['smfforum_num_recent_topics'] = array('#type' => 'textfield',
626 '#title' => t('Number of recent topics'),
627 '#maxlength' => '2', '#size' => '2',
628 '#default_value' => variable_get('smfforum_num_recent_topics', SMF_NUM_RECENT_TOPICS),
629 '#description' => t('Enter the number of recent topics.'));
630
631 $form['drupalsettings']['smfforum_recent_topics_br'] = array(
632 '#type' => 'radios',
633 '#title' => t('Recent topics word\'s delimiter'),
634 '#default_value' => variable_get('smfforum_recent_topics_br', 1),
635 '#options' => array(0 => t('Space'), 1 => t('BR')),
636 '#description' => t('Enter the recent topics word\'s delimiter.'));
637
638 $form['drupalsettings']['smfforum_num_recent_posts'] = array('#type' => 'textfield',
639 '#title' => t('Number of recent posts'),
640 '#maxlength' => '2', '#size' => '2',
641 '#default_value' => variable_get('smfforum_num_recent_posts', SMF_NUM_RECENT_POSTS),
642 '#description' => t('Enter the number of recent posts.'));
643
644 $form['drupalsettings']['smfforum_recent_posts_br'] = array(
645 '#type' => 'radios',
646 '#title' => t('Recent posts word\'s delimiter'),
647 '#default_value' => variable_get('smfforum_recent_posts_br', 1),
648 '#options' => array(0 => t('Space'), 1 => t('BR')),
649 '#description' => t('Enter the recent posts word\'s delimiter.'));
650
651 $form['drupalsettings']['smfforum_user_ban'] = array(
652 '#type' => 'radios',
653 '#title' => t('SMF user ban checking'),
654 '#default_value' => variable_get('smfforum_user_ban', 0),
655 '#options' => array(0 => t('No'), 1 => t('Check SMF bans')),
656 );
657
658 $form['drupalsettings']['smfforum_set_msg'] = array(
659 '#type' => 'radios',
660 '#title' => t('Display SMFforum module messages'),
661 '#default_value' => variable_get('smfforum_set_msg', 1),
662 '#options' => array(0 => t('No'), 1 => t('Yes')),
663 );
664
665 $form['drupalsettings']['smfforum_log_msg'] = array(
666 '#type' => 'radios',
667 '#title' => t('Log SMFforum module messages'),
668 '#default_value' => variable_get('smfforum_log_msg', 1),
669 '#options' => array(0 => t('No'), 1 => t('Yes')),
670 );
671
672 // Signatures
673 $form['drupalsettings']['smfforum_sync_signature'] = array(
674 '#type' => 'radios',
675 '#title' => t('Signatures synchronisation'),
676 '#default_value' => variable_get('smfforum_sync_signature', 1),
677 '#options' => array(0 => t('Disable'), 1 => t('Enable')),
678 '#description' => t('Set signatures synchronisation support.')
679 );
680 // Avatars
681 $form['drupalsettings']['smfforum_sync_avatar'] = array(
682 '#type' => 'radios',
683 '#title' => t('Avatars synchronisation'),
684 '#default_value' => variable_get('smfforum_sync_avatar', 1),
685 '#options' => array(0 => t('Disable'), 1 => t('Enable')),
686 '#description' => t('Set avatars synchronisation support.')
687 );
688 // Timezones
689 $form['drupalsettings']['smfforum_sync_timezone'] = array(
690 '#type' => 'radios',
691 '#title' => t('Timezones synchronisation'),
692 '#default_value' => variable_get('smfforum_sync_timezone', 0),
693 '#options' => array(0 => t('Disable'), 1 => t('Enable')),
694 '#description' => t('Set timezones synchronisation support.')
695 );
696
697 $form['profilemap'] = array('#type' => 'fieldset',
698 '#title' => t('Profile fields mapping'),
699 '#collapsible' => TRUE,
700 '#collapsed' => TRUE);
701
702 $form['profilemap']['smfforum_map_name'] = array('#type' => 'textfield',
703 '#title' => t('Name of `name` field'), // 'realName'
704 '#maxlength' => '128', '#size' => '60',
705 '#default_value' => variable_get('smfforum_map_name', 'profile_name'),
706 '#description' => t('Enter the name of SMF `realName` field, as it configured in Drupal profile module.'));
707
708 $form['profilemap']['smfforum_map_gender'] = array('#type' => 'textfield',
709 '#title' => t('Name of `gender` field'), // 'gender'
710 '#maxlength' => '128', '#size' => '60',
711 '#default_value' => variable_get('smfforum_map_gender', 'profile_gender'),
712 '#description' => t('Enter the name of SMF `gender` field, as it configured in Drupal profile module.'));
713
714 $form['profilemap']['smfforum_map_birthdate'] = array('#type' => 'textfield',
715 '#title' => t('Name of `birthdate` field'), // 'birthdate'
716 '#maxlength' => '128', '#size' => '60',
717 '#default_value' => variable_get('smfforum_map_birthdate', 'profile_birthdate'),
718 '#description' => t('Enter the name of SMF `birthdate` field, as it configured in Drupal profile module.'));
719
720 $form['profilemap']['smfforum_map_personalText'] = array('#type' => 'textfield',
721 '#title' => t('Name of `personalText` field'), // 'personalText'
722 '#maxlength' => '128', '#size' => '60',
723 '#default_value' => variable_get('smfforum_map_personalText', 'profile_personalText'),
724 '#description' => t('Enter the name of SMF `personalText` field, as it configured in Drupal profile module.'));
725
726 $form['profilemap']['smfforum_map_usertitle'] = array('#type' => 'textfield',
727 '#title' => t('Name of `usertitle` field'), // 'usertitle'
728 '#maxlength' => '128', '#size' => '60',
729 '#default_value' => variable_get('smfforum_map_usertitle', 'profile_usertitle'),
730 '#description' => t('Enter the name of SMF `usertitle` field, as it configured in Drupal profile module.'));
731
732 $form['profilemap']['smfforum_map_location'] = array('#type' => 'textfield',
733 '#title' => t('Name of `location` field'),
734 '#maxlength' => '128', '#size' => '60',
735 '#default_value' => variable_get('smfforum_map_location', 'profile_location'),
736 '#description' => t('Enter the name of SMF `location` field, as it configured in Drupal profile module.'));
737
738 $form['profilemap']['smfforum_map_ICQ'] = array('#type' => 'textfield',
739 '#title' => t('Name of `ICQ` field'),
740 '#maxlength' => '128', '#size' => '60',
741 '#default_value' => variable_get('smfforum_map_ICQ', 'profile_ICQ'),
742 '#description' => t('Enter the name of SMF `ICQ` field, as it configured in Drupal profile module.'));
743 $form['profilemap']['smfforum_map_AIM'] = array('#type' => 'textfield',
744 '#title' => t('Name of `AIM` field'),
745 '#maxlength' => '128', '#size' => '60',
746 '#default_value' => variable_get('smfforum_map_AIM', 'profile_AIM'),
747 '#description' => t('Enter the name of SMF `AIM` field, as it configured in Drupal profile module.'));
748 $form['profilemap']['smfforum_map_YIM'] = array('#type' => 'textfield',
749 '#title' => t('Name of `YIM` field'),
750 '#maxlength' => '128', '#size' => '60',
751 '#default_value' => variable_get('smfforum_map_YIM', 'profile_YIM'),
752 '#description' => t('Enter the name of SMF `YIM` field, as it configured in Drupal profile module.'));
753
754 $form['profilemap']['smfforum_map_MSN'] = array('#type' => 'textfield',
755 '#title' => t('Name of `MSN` field'),
756 '#maxlength' => '128', '#size' => '60',
757 '#default_value' => variable_get('smfforum_map_MSN', 'profile_MSN'),
758 '#description' => t('Enter the name of SMF `MSN` field, as it configured in Drupal profile module.'));
759
760 $form['profilemap']['smfforum_map_websiteTitle'] = array('#type' => 'textfield',
761 '#title' => t('Name of `websiteTitle` field'), // 'websiteTitle'
762 '#maxlength' => '128', '#size' => '60',
763 '#default_value' => variable_get('smfforum_map_websiteTitle', 'profile_websiteTitle'),
764 '#description' => t('Enter the name of SMF `websiteTitle` field, as it configured in Drupal profile module.'));
765
766 $form['profilemap']['smfforum_map_websiteUrl'] = array('#type' => 'textfield',
767 '#title' => t('Name of `websiteUrl` field'), // 'websiteUrl'
768 '#maxlength' => '128', '#size' => '60',
769 '#default_value' => variable_get('smfforum_map_websiteUrl', 'profile_websiteUrl'),
770 '#description' => t('Enter the name of SMF `websiteUrl` field, as it configured in Drupal profile module.'));
771
772
773 // Frame
774 $form['smfforum_page'] = array('#type' => 'fieldset',
775 '#title' => t('SMF page settings'),
776 '#collapsible' => TRUE,
777 '#collapsed' => FALSE);
778
779 $form['smfforum_page']['smfforum_page_frame'] = array(
780 '#type' => 'radios',
781 '#title' => t('SMF display way'),
782 '#default_value' => variable_get("smfforum_page_frame", 0),
783 '#options' => array(0 => t('In the window'), 1 => t('In frame inside Drupal page')),
784 '#description' => t("Change the way SMF is displayed in Drupal.")
785 );
786
787 $target = variable_get("smfforum_page_frame", 0);
788 if ($target == 1) {
789 $form['smfforum_page']['smfforum_page_width'] = array(
790 '#type' => 'textfield',
791 '#title' => t("SMF frame width"),
792 '#default_value' => variable_get("smfforum_page_width", "100%"),
793 '#size' => '6',
794 '#maxlength' => '6',
795 '#description' => t("Set the width of the Frame.")
796 );
797 $form['smfforum_page']['smfforum_page_height'] = array(
798 '#type' => 'textfield',
799 '#title' => t("SMF frame height"),
800 '#default_value' => variable_get("smfforum_page_height", "1024"),
801 '#size' => '6', '#maxlength' => '6',
802 '#description' => t("Set the height of the Frame.")
803 );
804
805 $form['smfforum_page']['smfforum_page_scroll'] = array(
806 '#type' => 'radios',
807 '#title' => t('Scrolling SMF frame'),
808 '#default_value' => variable_get("smfforum_page_scroll", 2),
809 '#options' => array(0 => t('No'), 1 => t('Yes'), 2 => t('Auto')),
810 '#description' => t("Should scrollbars be displayed if SMF is too large to fit in the frame.")
811 );
812 }
813 }
814 return $form;
815 }
816
817 if (variable_get("smfforum_page_frame", 0) == 1) {
818
819 function smfforum_page() {
820 global $smf_settings, $site_smf_page;
821 if (!_smfforum_settings())
822 return;
823
824 $action = $_SERVER['QUERY_STRING'];
825 //drupal_set_message('QUERY_STRING='.$action);
826
827 //$str = "q=smfforum";
828 $str = 'q='. $site_smf_page .'/index.php';
829 //$str = 'q='. $site_smf_page;
830 $len = strlen($str);
831 $stra = $str .'&';
832 $lena = $len + 1;
833 if (substr($action, 0, $lena) == $stra)
834 $action = substr($action, $lena);
835 elseif (substr($action, 0, $len) == $str)
836 $action = substr($action, $len);
837 else {
838 $str = 'q='. $site_smf_page;
839 $len = strlen($str);
840 $stra = $str .'&';
841 $lena = $len + 1;
842 if (substr($action, 0, $lena) == $stra)
843 $action = substr($action, $lena);
844 elseif (substr($action, 0, $len) == $str)
845 $action = substr($action, $len);
846 }
847
848 //drupal_set_message('QUERY_STRING2='.$action);
849
850 $path = $smf_settings['forum_url'];
851 $path .= '/index.php';
852 if ($action != "") {
853 $path .= '?';
854 $path .= $action;
855 }
856
857 //drupal_set_message('path='.$path);
858
859 // Added this to allow the iframe to resize dynamically according to the
860 // page height. -- Daen
861
862 drupal_add_js(drupal_get_path('module', 'smfforum') .'/smfframe.js', 'module');
863
864 $width = variable_get("smfforum_page_width", "100%");
865 $height = variable_get("smfforum_page_height", "1024");
866 $scrolling = variable_get("smfforum_page_scroll", 2);
867
868 $output = '<iframe id="forumFrame" src="'. $path .'"'; //name="smfforum"';
869
870 if ($width && $height) {
871 $output .= ' width="'. $width .'"'.' height="'. $height .'"';
872 }
873 $output .= ' frameborder="0" framespacing="0"';
874 if ($scrolling == 2)
875 $output .= ' scrolling="auto"';
876 elseif ($scrolling == 1)
877 $output .= ' scrolling="yes"';
878 else
879 $output .= ' scrolling="no"';
880 $output .= ' allowtransparency="false"';
881
882 $output .= '><p>'. t('Sorry your browser does not work') .'</p></iframe>';
883
884 return $output;
885 }
886 }
887
888 function smfforum_block($op = 'list', $delta = 0, $edit = array()) {
889 global $user;
890
891 if ($op == 'list') {
892 $blocks[0]['info'] = SMF_MODULE_TAG .': '. t('Hidden authentication');
893 $blocks[1]['info'] = SMF_MODULE_TAG .': '. t('Personal messages');
894 $blocks[2]['info'] = SMF_MODULE_TAG .': '. t('Online forum users');
895 $blocks[3]['info'] = SMF_MODULE_TAG .': '. t('New forum topics');
896 $blocks[4]['info'] = SMF_MODULE_TAG .': '. t('New forum posts');
897 $blocks[5]['info'] = SMF_MODULE_TAG .': '. t('Forum statistics');
898 $blocks[6]['info'] = SMF_MODULE_TAG .': '. t('Top posters');
899 return $blocks;
900 }
901 else if ($op == 'view') {
902
903 $block = array();
904
905 if (!_smfforum_settings())
906 return $block;
907
908 switch ($delta) {
909 case 0:
910 _smfforum_authenticate_user();
911 return $block;
912
913 case 1:
914
915 $c = smfforum_pm();
916 $block['subject'] = t('Personal messages');
917 $block['content'] = $c;
918 return $block;
919
920 case 2:
921
922 $c = smfforum_whos_online((int)variable_get('smfforum_num_whos_online', SMF_NUM_WHOS_ONLINE));
923 $block['subject'] = t('Online forum users');
924 $block['content'] = $c;
925 return $block;
926
927 case 3:
928
929 if (variable_get('smfforum_recent_topics_br', 1))
930 $delimeter = SMF_RECENT_DELIMITER_BR;
931 else
932 $delimeter = SMF_RECENT_DELIMITER_SPACE;
933 $c = smfforum_recent_topics((int)variable_get('smfforum_num_recent_topics', SMF_NUM_RECENT_TOPICS), null, "<ul class = \"menu\">", $delimeter);
934 $block['subject'] = t('New forum topics');
935 $block['content'] = $c;
936 return $block;
937
938 case 4:
939
940 if (variable_get('smfforum_recent_posts_br', 1))
941 $delimeter = SMF_RECENT_DELIMITER_BR;
942 else
943 $delimeter = SMF_RECENT_DELIMITER_SPACE;
944 $c = smfforum_recent_posts((int)variable_get('smfforum_num_recent_posts', SMF_NUM_RECENT_POSTS), null, "<ul class = \"menu\">", $delimeter);
945 $block['subject'] = t('New forum posts');
946 $block['content'] = $c;
947 return $block;
948
949 case 5:
950
951 $c = smfforum_board_stats();
952 $block['subject'] = t('Forum statistics');
953 $block['content'] = $c;
954 return $block;
955
956 case 6:
957
958 $c = smfforum_topposter((int)variable_get('smfforum_num_top_posters', SMF_NUM_TOP_POSTERS));
959 $block['subject'] = t('Top posters');
960 $block['content'] = $c;
961 return $block;
962 }
963 }
964 }
965
966 function _smfforum_watchdog($message = '', $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL) {
967 if (empty($message))
968 return;
969 $display = variable_get("smfforum_log_msg", 0);
970 if (!$display)
971 return;
972
973 if (SMF_DRUPAL_MODULE_VERSION == 5) {
974 if (count($variables) != 0)
975 $message = t($message, $variables);
976 watchdog(SMF_DRUPAL_MODULE, $message, $severity, $link);
977 }
978 else {
979 watchdog(SMF_DRUPAL_MODULE, $message, $variables, $severity, $link);
980 }
981 return;
982 }
983
984 function _smfforum_set_message($message, $variables = array(), $type = 'status', $repeat = TRUE) {
985 if (empty($message))
986 return;
987 $display = variable_get("smfforum_set_msg", 0);
988 if (!$display)
989 return;
990
991 if (count($variables) != 0)
992 $message = t($message, $variables);
993
994 if (SMF_DRUPAL_MODULE_VERSION == 5) {
995 drupal_set_message($message, $type);
996 }
997 else {
998 drupal_set_message($message, $type, $repeat);
999 }
1000 return;
1001 }
1002
1003
1004 function _smfforum_msg($op = 'info', $update = false, $msg = '', $msgt = '', $account = '', $edit = array()) {
1005
1006 global $smf_settings, $smf_user_info, $user;
1007 $message = '';
1008
1009 $name = (empty($account) ? smf_api_utf8($smf_user_info['username']) : $account->name);
1010
1011 if ($op == 'update' || $op == 'after_update' || $op == 'insert' || $op == 'login' || $op == 'login2' || $op == 'view' || $op == 'categories') {
1012 if (count($edit) != 0) {
1013 $s = '';
1014 foreach ($edit as $var => $val) {
1015 if ($var == 'pass' || $var == 'passwd')
1016 $s .= "$var => ****, ";
1017 else {
1018 if ($msgt == SMF_SYNC_TO_SMF)
1019 $var = variable_get('smfforum_map_'. $var, '');
1020 if (!empty($var)) {
1021 // 01234567
1022 // profile_
1023 if (substr($var, 0, 8) == "profile_")
1024 $var = substr($var, 8);
1025
1026 if ($var == 'gender' && $msgt == SMF_SYNC_TO_SMF) {
1027 if ($val == '1')
1028 $val = t('Male');
1029 elseif ($val == '2')
1030 $val = t('Female');
1031 }
1032 $s .= "$var => $val, ";
1033 }
1034 }
1035 }
1036 if ($msgt == SMF_SYNC_TO_SMF)
1037 $s = smf_api_utf8($s);
1038 }
1039
1040 if ($update && count($edit) != 0) {
1041 $message = t('Data %data for %name synced', array('%data' => $s, '%name' => $name));
1042 }
1043 else if (!$update && count($edit) != 0)
1044 $message = t('Unable to sync data %data for %name', array('%data' => $s, '%name' => $name));
1045 else
1046 $message = t('No data to sync for %name', array('%name' => $name));
1047
1048 //$msgt = t('%smfforum_to', array('%smfforum_to' => $msgt));
1049 if (