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

Diff of /contributions/modules/phpbb/phpbb.module

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

revision 1.14, Tue Oct 24 22:48:30 2006 UTC revision 1.15, Sat Feb 10 19:38:49 2007 UTC
# Line 7  Line 7 
7   * Many thanks to: Jimbo, brdwor   * Many thanks to: Jimbo, brdwor
8   */   */
9    
   
10  /**  /**
11   * Implementation of hook_help   * Implementation of hook_help
12   */   */
13  function phpbb_help($section) {  function phpbb_help($section) {
14          switch($section) {          switch($section) {
15                  case 'admin/modules#description':          case 'admin/modules#description':
16                  return t('Integration with phpBB');                  return t('Integration with phpBB');
17    }          }
18  }  }
19    
20  /**  /**
21   * Implementation of hook_settings   * Implementation of hook_settings
22   */   */
23  function phpbb_settings() {  function phpbb_settings() {
24    $form['phpbb_dir'] = array(                  $form['phpbb_dir'] = array(
25      '#type' => 'textfield',                  '#type' => 'textfield',
26      '#title' => t('Location of phpbb'),                  '#title' => t('Location of phpbb'),
27      '#default_value' => variable_get('phpbb_dir', 'phpBB2/'),                  '#default_value' => variable_get('phpbb_dir', 'phpBB2/'),
28      '#size' => 64,                  '#size' => 64,
29      '#maxlength' => 64,                  '#maxlength' => 64,
30      '#description' => t('relative path to your phpBB2 directory. Please include a trailing slash ("/").'),                  '#description' => t('relative path to your phpBB2 directory. Please include a trailing slash ("/").'),
31    );          );
32   $form['phpbb_www_path'] = array(          $form['phpbb_www_path'] = array(
33      '#type' => 'textfield',                  '#type' => 'textfield',
34      '#title' => t('Absolute path to phpbb'),                  '#title' => t('Absolute path to phpbb'),
35      '#default_value' => variable_get('phpbb_www_path', '/phpBB2/'),                  '#default_value' => variable_get('phpbb_www_path', '/phpBB2/'),
36      '#size' => 64,                  '#size' => 64,
37      '#maxlength' => 64,                  '#maxlength' => 64,
38      '#description' => t('The absolute path as seen by the webbrowser. Has to include starting and trailing slashes ("/"). Example: http://www.someplace.com/drupal/forum -> /drupal/forum/'),                  '#description' => t('The absolute path as seen by the webbrowser, including slashes ("/"). Example: http://www.someplace.com/drupal/forum -> /drupal/forum/'),
39    );          );
40    
41          $form['phpbb_block0_title'] = array(          $form['phpbb_block0_title'] = array(
42                  '#type' => 'textfield',                  '#type' => 'textfield',
43      '#title' => t('Title of sidebar block'),                  '#title' => t('Title of sidebar block'),
44      '#default_value' => variable_get('phpbb_block0_title', 'phpBB Topics'),                  '#default_value' => variable_get('phpbb_block0_title', 'phpBB Topics'),
45      '#size' => 64,                  '#size' => 64,
46      '#maxlength' => 64,                  '#maxlength' => 64,
47      '#description' => t('Title to use for the "recent topics" sidebar'),                  '#description' => t('Title to use for the "recent topics" sidebar'),
48    );          );
49          $form['phpbb_forum_enc'] = array(          $form['phpbb_forum_enc'] = array(
50                  '#type' => 'textfield',                  '#type' => 'textfield',
51      '#title' => t('Character encoding used in phpBB'),                  '#title' => t('Character encoding used in phpBB'),
52      '#default_value' => variable_get('phpbb_forum_enc', 'ISO-8859-1'),                  '#default_value' => variable_get('phpbb_forum_enc', 'ISO-8859-1'),
53      '#size' => 64,                  '#size' => 64,
54      '#maxlength' => 64,                  '#maxlength' => 64,
55      '#description' => t('Usually ISO-8859-1'),                  '#description' => t('Usually ISO-8859-1'),
56    );          );
57          $form['phpbb_drupal_enc'] = array(          $form['phpbb_drupal_enc'] = array(
58                  '#type' => 'textfield',                  '#type' => 'textfield',
59      '#title' => t('Character encoding used in Drupal'),                  '#title' => t('Character encoding used in Drupal'),
60      '#default_value' => variable_get('phpbb_drupal_enc', 'UTF-8'),                  '#default_value' => variable_get('phpbb_drupal_enc', 'UTF-8'),
61      '#size' => 64,                  '#size' => 64,
62      '#maxlength' => 64,                  '#maxlength' => 64,
63      '#description' => t('Usually UTF-8'),                  '#description' => t('Usually UTF-8'),
64    );          );
65    
66    return $form;    return $form;
67  }  }
# Line 73  function phpbb_settings() { Line 72  function phpbb_settings() {
72  function phpbb_user($op, &$edit, &$user, $category = NULL) {  function phpbb_user($op, &$edit, &$user, $category = NULL) {
73          /* Get a connection to phpBBs database. */          /* Get a connection to phpBBs database. */
74          $phpbb_dbc = _phpbb_db();          $phpbb_dbc = _phpbb_db();
75            if(! $phpbb_dbc ) {
76                    return "";
77            }
78          $prefix = _phpbb_prefix();          $prefix = _phpbb_prefix();
79    
80          switch ($op) {          switch ($op) {
# Line 131  function phpbb_user($op, &$edit, &$user, Line 133  function phpbb_user($op, &$edit, &$user,
133                                  $res = mysql_query($query, $phpbb_dbc) or die('Query failed: ' . mysql_error() . " \n" . $query . "\n");                                  $res = mysql_query($query, $phpbb_dbc) or die('Query failed: ' . mysql_error() . " \n" . $query . "\n");
134                          }                          }
135    
                 //Commented out because storing avatars off-site is bad (security and speed).  
   
                 //if(array_key_exists('phpbb_avatar_url', $edit)) {  
                 //      if ($edit['phpbb_avatar_url'] != "") {  
                 //              $query =        "UPDATE " . $prefix ."users SET `user_avatar`='" . $edit['phpbb_avatar_url'] . "', `user_avatar_type`=2 WHERE `user_id`=".$user->uid;  
                 //              $res = mysql_query($query, $phpbb_dbc) or die('Query failed: ' . mysql_error() . " \n" . $query . "\n");  
                 //      } elseif ($user->picture != "") {  
                 //              # if the url had been blanked, ensure that the drupal picure is set, if any  
                 //              $query =        "UPDATE " . $prefix ."users SET `user_avatar`='" . $user->picture . "', `user_avatar_type`=1 WHERE `user_id`=".$user->uid;  
                 //              $res = mysql_query($query, $phpbb_dbc) or die('Query failed: ' . mysql_error() . " \n" . $query . "\n");  
                 //      }  
                 //}  
   
136                  /* Go through the user defined fields in Drupal */                  /* Go through the user defined fields in Drupal */
137                          if(module_exist('profile'))                          if(module_exist('profile'))
138                                  _phpbb_update_profile_fields($edit, $user, $phpbb_dbc, $prefix);                                  _phpbb_update_profile_fields($edit, $user, $phpbb_dbc, $prefix);
139                  break;                  break;
140    
141                  case 'delete':                  case 'delete':
142                  $query =        "DELETE FROM " . $prefix . "users WHERE user_id=" . $user->uid . " LIMIT 1";                          $query =        "DELETE FROM " . $prefix . "users WHERE user_id=" . $user->uid . " LIMIT 1";
143                  $res = mysql_query($query, $phpbb_dbc) or die('Query failed: ' . mysql_error() . " \n" . $query . "\n");                          $res = mysql_query($query, $phpbb_dbc) or die('Query failed: ' . mysql_error() . " \n" . $query . "\n");
144                  $query =                "DELETE FROM " . $prefix . "groups WHERE `group_id` = " . $user->uid . " LIMIT 1";                          $query =                "DELETE FROM " . $prefix . "groups WHERE `group_id` = " . $user->uid . " LIMIT 1";
145                  $res = mysql_query($query, $phpbb_dbc) or die('Query failed: ' . mysql_error() . " \n" . $query . "\n");                          $res = mysql_query($query, $phpbb_dbc) or die('Query failed: ' . mysql_error() . " \n" . $query . "\n");
146                  $query =                "DELETE FROM " . $prefix . "user_group WHERE `user_id` =" . $user->uid;                          $query =                "DELETE FROM " . $prefix . "user_group WHERE `user_id` =" . $user->uid;
147                  $res = mysql_query($query, $phpbb_dbc) or die('Query failed: ' . mysql_error() . " \n" . $query . "\n");                          $res = mysql_query($query, $phpbb_dbc) or die('Query failed: ' . mysql_error() . " \n" . $query . "\n");
148          break;          break;
149    
150          case 'login':          case 'login':
# Line 170  function phpbb_user($op, &$edit, &$user, Line 159  function phpbb_user($op, &$edit, &$user,
159                          }                          }
160    
161                          if($user->signature) {                          if($user->signature) {
162                                  $new_edit['signature'] = $user->signature;                                  $new_edit['signature'] = _phpbb_encode($user->signature);
163                          }                          }
164    
165                          $profile_fields = array('user_interests', 'user_aim', 'user_msnm', 'user_yim', 'user_website', 'user_from', 'user_occ', 'user_icq', 'user_notify', 'user_attachsig', 'user_allow_viewonline');                          $profile_fields = array('user_interests', 'user_aim', 'user_msnm', 'user_yim', 'user_website', 'user_from',
166                                                                                            'user_occ', 'user_icq', 'user_notify', 'user_attachsig', 'user_allow_viewonline');
167    
168                          foreach ($profile_fields as $afield) {                          foreach ($profile_fields as $afield) {
169                                  if ($aval = _phpbb_get_profile_value($afield)) {                                  if ($aval = _phpbb_get_profile_value($afield)) {
# Line 183  function phpbb_user($op, &$edit, &$user, Line 173  function phpbb_user($op, &$edit, &$user,
173    
174                          phpbb_user('insert',$new_edit,$user);                          phpbb_user('insert',$new_edit,$user);
175                  } else {                  } else {
176                          //$query =      "UPDATE " . $prefix ."users SET `user_password`='" . _phpbb_encode($user->pass) . "' WHERE `user_id`=".$user->uid;                          $query =        "UPDATE " . $prefix ."users SET `user_password`='" . _phpbb_encode($user->pass) .
177                          //If you want to control administrators directly, not recommended. Keep the first user separately for phpBB administration                                                          "', `user_level`='" . (user_access('administer phpbb') ? 1 : 0) . "', `username`='"
178                                                  $query =        "UPDATE " . $prefix ."users SET `user_password`='" . _phpbb_encode($user->pass) . "', `user_level`='" . (user_access('administer phpbb') ? 1 : 0) . "', `username`='".$user->name ."' WHERE `user_id`=".$user->uid;                                                          ._phpbb_encode($user->name) ."' WHERE `user_id`=".$user->uid;
179                          $res = mysql_query($query, $phpbb_dbc) or die('Query failed: ' . mysql_error() . " \n" . $query . "\n");                          $res = mysql_query($query, $phpbb_dbc) or die('Query failed: ' . mysql_error() . " \n" . $query . "\n");
180                  }                  }
181    
# Line 203  function phpbb_user($op, &$edit, &$user, Line 193  function phpbb_user($op, &$edit, &$user,
193          break;          break;
194    
195  case 'view':  case 'view':
196    $form = array();          $form = array();
197    $output = array();          $output = array();
198    $query = "SELECT post_id FROM " . $prefix ."posts WHERE `poster_id`= ". $user->uid ;          $query = "SELECT post_id FROM " . $prefix ."posts WHERE `poster_id`= ". $user->uid ;
199    $post_res = mysql_query($query, $phpbb_dbc) or die('Query failed: ' . mysql_error() . " \n" . $query . "\n");          $post_res = mysql_query($query, $phpbb_dbc) or die('Query failed: ' . mysql_error() . " \n" . $query . "\n");
200    
201    $query = "SELECT topic_id FROM " . $prefix ."topics WHERE `topic_poster`= ". $user->uid ;          $query = "SELECT topic_id FROM " . $prefix ."topics WHERE `topic_poster`= ". $user->uid ;
202    $topic_res = mysql_query($query, $phpbb_dbc) or die('Query failed: ' . mysql_error() . " \n" . $query . "\n");          $topic_res = mysql_query($query, $phpbb_dbc) or die('Query failed: ' . mysql_error() . " \n" . $query . "\n");
203    
204    //$form['forum_topics'] = array(          $items['no_topics'] = array('title' => t('Antall tråder startet:'),
   //    '#type' => 'item',  
   //    '#title' => t('Number of topics started'),  
   //    '#value' => mysql_num_rows($topic_res),  
   //);  
   //$form['forum_posts'] = array(  
   //    '#type' => 'item',  
   //    '#title' => t('Number of posts'),  
   //    '#value' => mysql_num_rows($post_res),  
   //);  
   
   //$output['Forum'] = array(drupal_get_form('forum', $form));  
                 $items['no_topics'] = array('title' => t('Number of topics started'),  
205        'value' => mysql_num_rows($topic_res),        'value' => mysql_num_rows($topic_res),
206        'class' => 'member'        'class' => 'member'
207      );      );
208                  $items['no_posts'] = array('title' => t('Number of posts'),                  $items['no_posts'] = array('title' => t('Antall innlegg:'),
209        'value' => mysql_num_rows($post_res),        'value' => mysql_num_rows($post_res),
210        'class' => 'member'        'class' => 'member'
211      );      );
# Line 235  case 'view': Line 213  case 'view':
213      return array(t('Forum') => $items);      return array(t('Forum') => $items);
214    
215  break;  break;
   
216   }   }
217          return $output;          return $output;
218  }  }
# Line 272  function phpbb_block($op = 'list', $delt Line 249  function phpbb_block($op = 'list', $delt
249  }  }
250    
251  /**  /**
252     * Implementation of hook_menu().
253     */
254    function phpbb_menu($may_cache) {
255      $items = array();
256    
257      if ($may_cache) {
258        $items[] = array('path' => 'phpbb', 'title' => t('phpbb'),
259          'callback' => 'phpbb_view',
260          'access' => TRUE,
261                    'type' => MENU_SUGGESTED_ITEM);
262      }
263      return $items;
264    }
265    
266    /**
267     * Menu callback; presents the phpbbsup form and/or phpbbsup results.
268     */
269    function phpbb_view() {
270            global $user;
271    
272            if($user->uid == 0) {
273                    //echo $forum_goto . " " . arg(2);
274                    watchdog('user', t('phpBB bounce for %name.', array('%name' => theme('placeholder', $user->name))));
275                    session_destroy();
276                    $user = user_load(array('uid' => 0));
277                    drupal_goto('user/login?destination=' . variable_get('phpbb_dir', 'phpBB2/') . arg(1));
278            } else {
279                    // We know who this is, create session and send them back
280                    watchdog('user', t('phpBB rebuffed %name.', array('%name' => theme('placeholder', $user->name))));
281                    $edit = array();
282                    phpbb_user('logout',$edit, $user);
283                    phpbb_user('login',$edit, $user);
284                    drupal_goto(variable_get('phpbb_dir', 'phpBB2/') . arg(1));
285            }
286    }
287    
288    /**
289   * Get the configuration and create a database-resource   * Get the configuration and create a database-resource
290   */   */
291  function _phpbb_db() {  function _phpbb_db() {
292          $phpbb_root_path = variable_get('phpbb_dir', 'phpBB2/');          $phpbb_root_path = variable_get('phpbb_dir', 'phpBB2/');
293          include($phpbb_root_path.'config.php');          include($phpbb_root_path.'config.php');
294          if ($dbms) {          if ($dbms) {
         //if ($dbms == 'mysql4'|| $dbms == 'mysql3' || $dbms == 'mysql') {  
295                  $dbms = 'mysql';                  $dbms = 'mysql';
296          } else {          } else {
297                  die('Could not open '. $phpbb_root_path.'config.php for inclusion');                  return;
298          }          }
299    
300          //$phpbb_dbc=db_connect($dbms.'://'.$dbuser.':'.$dbpasswd.'@'.$dbhost.'/'.$dbname);          //$phpbb_dbc=db_connect($dbms.'://'.$dbuser.':'.$dbpasswd.'@'.$dbhost.'/'.$dbname);
# Line 300  function _phpbb_prefix() { Line 313  function _phpbb_prefix() {
313  function _phpbb_update_profile_fields(&$edit,&$user,&$phpbb_dbc, &$prefix) {  function _phpbb_update_profile_fields(&$edit,&$user,&$phpbb_dbc, &$prefix) {
314          foreach ($edit as $akey => $aval) {          foreach ($edit as $akey => $aval) {
315          switch ($akey) {          switch ($akey) {
316                  case 'signature':                  case 'signature':
317                          $akey = 'user_sig';                  $akey = 'user_sig';
318                          case 'user_interests':  
319                          case 'user_aim':                  case 'user_interests':
320                          case 'user_msnm':                  case 'user_aim':
321                          case 'user_yim':                  case 'user_msnm':
322                          _phpbb_update_profile_field($akey,substr($aval,0,255),$user,$phpbb_dbc, $prefix);                  case 'user_yim':
323                          break;                  _phpbb_update_profile_field($akey,substr($aval,0,255),$user,$phpbb_dbc, $prefix);
324                    break;
325    
326                          case 'user_website':                  case 'user_website':
327                          case 'user_from':                  case 'user_from':
328                          case 'user_occ':                  case 'user_occ':
329                                  _phpbb_update_profile_field($akey,substr($aval,0,100),$user,$phpbb_dbc, $prefix);                          _phpbb_update_profile_field($akey,substr($aval,0,100),$user,$phpbb_dbc, $prefix);
330                          break;                  break;
331    
332                          case 'user_icq':                  case 'user_icq':
333                                  _phpbb_update_profile_field($akey,substr($aval,0,15),$user,$phpbb_dbc, $prefix);                          _phpbb_update_profile_field($akey,substr($aval,0,15),$user,$phpbb_dbc, $prefix);
334                          break;                  break;
335    
336                          case 'user_notify':                  case 'user_notify':
337                                  //Inverted, default is to send emails                          //Inverted, default is to send emails
338                                  if($aval == 0) {                          if($aval == 0) {
339                                          $aval = 1;                                  $aval = 1;
340                                  } else {                          } else {
341                                          $aval = 0;                                  $aval = 0;
342                                  }                          }
343                                  _phpbb_update_profile_field($akey,$aval,$user,$phpbb_dbc, $prefix);                          _phpbb_update_profile_field($akey,$aval,$user,$phpbb_dbc, $prefix);
344                          break;                  break;
345    
346                          case 'user_attachsig':                  case 'user_attachsig':
347                                  _phpbb_update_profile_field($akey,substr($aval,0,15),$user,$phpbb_dbc, $prefix);                          _phpbb_update_profile_field($akey,substr($aval,0,15),$user,$phpbb_dbc, $prefix);
348                          break;                  break;
349                  }                  }
350          }          }
351  }  }
# Line 344  function _phpbb_update_profile_field($ak Line 358  function _phpbb_update_profile_field($ak
358  function _phpbb_get_profile_value($akey) {  function _phpbb_get_profile_value($akey) {
359          // This code does not honor table-prefixes!          // This code does not honor table-prefixes!
360          global $user;          global $user;
361          $result = db_query("SELECT profile_values.value AS value          $result = db_query(     "SELECT profile_values.value AS value FROM profile_values, profile_fields
362                  FROM profile_values, profile_fields                                                                  WHERE profile_fields.fid = profile_values.fid AND profile_fields.name = 'phpbb_".$akey."'
363                  WHERE profile_fields.fid = profile_values.fid                                                                  AND profile_values.uid = '".$user->uid."'");
                 AND profile_fields.name = 'phpbb_".$akey."'  
                 AND profile_values.uid = '".$user->uid."'");  
364    
365          if (db_num_rows($result) == 1) {          if (db_num_rows($result) == 1) {
366                  $arow = db_fetch_array($result);                  $arow = db_fetch_array($result);
# Line 460  function _phpbb_encoded_client_ip() { Line 472  function _phpbb_encoded_client_ip() {
472  function _phpbb_display_block_0() {  function _phpbb_display_block_0() {
473          $phpbb_dbc = _phpbb_db();          $phpbb_dbc = _phpbb_db();
474          $prefix = _phpbb_prefix();          $prefix = _phpbb_prefix();
475    
476          // auth_read = 0  -> we only include public forums          // auth_read = 0  -> we only include public forums
477          $phpbb_query =  'SELECT '.$prefix.'topics.topic_id, '.$prefix.'topics.topic_title, '.$prefix.'topics.topic_last_post_id FROM '          $phpbb_query = 'SELECT '.$prefix.'topics.topic_id, '.$prefix.'topics.topic_title, '.$prefix.'topics.topic_last_post_id FROM '
478                                                                          .$prefix.'topics LEFT JOIN '.$prefix.'forums ON '.$prefix.'topics.forum_id = '.$prefix.'forums.forum_id WHERE '                                                  .$prefix.'topics LEFT JOIN '.$prefix.'forums ON '.$prefix.'topics.forum_id = '.$prefix.'forums.forum_id WHERE '
479                                                                          .$prefix.'forums.auth_view = 0 ORDER BY topic_last_post_id DESC LIMIT 10;';                                                  .$prefix.'forums.auth_view = 0 ORDER BY topic_last_post_id DESC LIMIT 10;';
480    
481          $result = mysql_query($phpbb_query, $phpbb_dbc) or die('Query failed: ' . mysql_error() . " \n</br></br>" . $phpbb_query . "\n");          $result = mysql_query($phpbb_query, $phpbb_dbc) or die('Query failed: ' . mysql_error() . " \n" . $phpbb_query . "\n");
482    
483          $list = array();          $list = array();
484    
485          while ($a_row = mysql_fetch_assoc($result) ){          while ($a_row = mysql_fetch_assoc($result) ){
486                          $descstr = _phpbb_decode($a_row['topic_title']);                  $descstr = _phpbb_decode($a_row['topic_title']);
487                          $origdescstr = $descstr;                  $origdescstr = $descstr;
488                    if (strlen($descstr) > 31 )
489                            $descstr = substr($descstr,0,29) . "...";
490    
491                          if (strlen($descstr) > 31 )                  $topic_urlstr = variable_get('phpbb_www_path', '/phpBB2/') ."viewtopic.php?t=" . $a_row['topic_id'];
492                                  $descstr = substr($descstr,0,29) . "...";                  $post_urlstr =  variable_get('phpbb_www_path', '/phpBB2/') ."viewtopic.php?p=" . $a_row['topic_last_post_id'] . "#" . $a_row['topic_last_post_id'];
   
                         $topic_urlstr = variable_get('phpbb_www_path', '/phpBB2/') ."viewtopic.php?t=" . $a_row['topic_id'];  
       $post_urlstr =  variable_get('phpbb_www_path', '/phpBB2/') ."viewtopic.php?p=" . $a_row['topic_last_post_id'] . "#" . $a_row['topic_last_post_id'];  
493    
494                          $list[] = '<a href="' . $post_urlstr .'"><img src="misc/arrow.gif" alt=">>" height="12" width="12" /></a> <a href="'. $topic_urlstr .'" title="'. $origdescstr . '">&nbsp;&nbsp;' . $descstr . '</a>';                  $list[] = '<a href="' . $post_urlstr .'"> <span class="pilned"></span></a> <a href="'
495                                            . $topic_urlstr .'" title="' . $origdescstr . '">' . $descstr . '</a> ' . "\n";
496          }          }
497          return theme('item_list', $list);  
498            return theme('item_list', $list);
499  }  }
500  ?>  ?>

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

  ViewVC Help
Powered by ViewVC 1.1.2