/[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.17, Wed Mar 28 20:52:39 2007 UTC revision 1.18, Wed Mar 28 21:06:14 2007 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: phpbb.module,v 1.16 2007/03/02 01:13:36 arkepp Exp $  // $Id: phpbb.module,v 1.15 2007/02/10 19:38:49 arkepp Exp $
3    
4  /**  /**
5   * http://drupal.org/node/32818   * http://drupal.org/node/32818
6   * See INSTALL.txt, you also need phpbb.htaccess   * See INSTALL.txt, you also need phpbb.htaccess
7   * Many thanks to: Jimbo, brdwor   * Many thanks to: Jimbo, brdwor for general patches
8     *
9     * Drupal 5.1 port by: maartenvg
10   */   */
11    
12  /**  /**
13   * Implementation of hook_help   * Implementation of hook_help
14   */   */
15  function phpbb_help($section) {  
16          switch($section) {  
17          case 'admin/modules#description':  function phpbb_admin_settings() {
18                  return t('Integration with phpBB');    $form['phpbb_dir'] = array(
         }  
 }  
   
 /**  
  * Implementation of hook_settings  
  */  
 function phpbb_settings() {  
                 $form['phpbb_dir'] = array(  
19                  '#type' => 'textfield',                  '#type' => 'textfield',
20                  '#title' => t('Location of phpbb'),                  '#title' => t('Location of phpbb'),
21                  '#default_value' => variable_get('phpbb_dir', 'phpBB2/'),                  '#default_value' => variable_get('phpbb_dir', 'phpBB2/'),
# Line 29  function phpbb_settings() { Line 23  function phpbb_settings() {
23                  '#maxlength' => 64,                  '#maxlength' => 64,
24                  '#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 ("/").'),
25          );          );
26    
27          $form['phpbb_www_path'] = array(          $form['phpbb_www_path'] = array(
28                  '#type' => 'textfield',                  '#type' => 'textfield',
29                  '#title' => t('Absolute path to phpbb'),                  '#title' => t('Absolute path to phpbb'),
# Line 46  function phpbb_settings() { Line 41  function phpbb_settings() {
41                  '#maxlength' => 64,                  '#maxlength' => 64,
42                  '#description' => t('Title to use for the "recent topics" sidebar'),                  '#description' => t('Title to use for the "recent topics" sidebar'),
43          );          );
44    
45          $form['phpbb_forum_enc'] = array(          $form['phpbb_forum_enc'] = array(
46                  '#type' => 'textfield',                  '#type' => 'textfield',
47                  '#title' => t('Character encoding used in phpBB'),                  '#title' => t('Character encoding used in phpBB'),
# Line 54  function phpbb_settings() { Line 50  function phpbb_settings() {
50                  '#maxlength' => 64,                  '#maxlength' => 64,
51                  '#description' => t('Usually ISO-8859-1'),                  '#description' => t('Usually ISO-8859-1'),
52          );          );
53    
54          $form['phpbb_drupal_enc'] = array(          $form['phpbb_drupal_enc'] = array(
55                  '#type' => 'textfield',                  '#type' => 'textfield',
56                  '#title' => t('Character encoding used in Drupal'),                  '#title' => t('Character encoding used in Drupal'),
# Line 63  function phpbb_settings() { Line 60  function phpbb_settings() {
60                  '#description' => t('Usually UTF-8'),                  '#description' => t('Usually UTF-8'),
61          );          );
62    
63    return $form;    return system_settings_form($form);
64  }  }
65    
66  /**  /**
# Line 102  function phpbb_user($op, &$edit, &$user, Line 99  function phpbb_user($op, &$edit, &$user,
99                                  $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");
100    
101                          /* Go through the user defined fields in Drupal*/                          /* Go through the user defined fields in Drupal*/
102                          if(module_exist('profile'))                          if(module_exists('profile'))
103                                  _phpbb_update_profile_fields($edit, $user,$phpbb_dbc, $prefix);                                  _phpbb_update_profile_fields($edit, $user,$phpbb_dbc, $prefix);
104                  break;                  break;
105    
# Line 134  function phpbb_user($op, &$edit, &$user, Line 131  function phpbb_user($op, &$edit, &$user,
131                          }                          }
132    
133                  /* Go through the user defined fields in Drupal */                  /* Go through the user defined fields in Drupal */
134                          if(module_exist('profile'))                          if(module_exists('profile'))
135                                  _phpbb_update_profile_fields($edit, $user, $phpbb_dbc, $prefix);                                  _phpbb_update_profile_fields($edit, $user, $phpbb_dbc, $prefix);
136                  break;                  break;
137    
# Line 192  function phpbb_user($op, &$edit, &$user, Line 189  function phpbb_user($op, &$edit, &$user,
189                  _phpbb_unset_cookies($phpbb_cookie_name);                  _phpbb_unset_cookies($phpbb_cookie_name);
190          break;          break;
191    
192  case 'view':    case 'view':
193          $form = array();      $form = array();
194          $output = array();      $output = array();
195          $query = "SELECT post_id FROM " . $prefix ."posts WHERE `poster_id`= ". $user->uid ;      $query = "SELECT post_id FROM " . $prefix ."posts WHERE `poster_id`= ". $user->uid ;
196          $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");
197    
198          $query = "SELECT topic_id FROM " . $prefix ."topics WHERE `topic_poster`= ". $user->uid ;      $query = "SELECT topic_id FROM " . $prefix ."topics WHERE `topic_poster`= ". $user->uid ;
199          $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");
200    
201          $items['no_topics'] = array('title' => t('Number of topics in phpBB:'),      $items['no_topics'] = array('title' => t('Number of topics in phpBB:'),
202        'value' => mysql_num_rows($topic_res),          'value' => mysql_num_rows($topic_res),
203        'class' => 'member'          'class' => 'member'
204      );        );
205                  $items['no_posts'] = array('title' => t('Numer of posts in phpBB'),      $items['no_posts'] = array('title' => t('Number of posts in phpBB:'),
206        'value' => mysql_num_rows($post_res),        'value' => mysql_num_rows($post_res),
207        'class' => 'member'        'class' => 'member'
208      );      );
209    
210      return array(t('Forum') => $items);      return array(t('Forum') => $items);
211    
212  break;    break;
213   }   }
214          return $output;   return $output;
215  }  }
216  /**  /**
217   * Implementation of hook_perm().   * Implementation of hook_perm().
# Line 229  function phpbb_perm() { Line 226  function phpbb_perm() {
226   *   *
227   */   */
228  function phpbb_block($op = 'list', $delta = 0, $edit = array() ) {  function phpbb_block($op = 'list', $delta = 0, $edit = array() ) {
229    switch ($op) {    if ($op == 'list') {
230      case 'list':      $blocks[0]['info'] = variable_get('phpbb_block0_title', t('phpBB Topics'));
231        $blocks[0]['info'] = t(variable_get('phpbb_block0_title','phpBB Topics'));           return $blocks;
232        return $blocks;    }
233      case 'configure':    else {
234        $form = array();      switch ($delta) {
235        return $form;        case 0:
236      case 'save':                          $block['subject'] = variable_get('phpbb_block0_title', t('phpBB Topics'));
237        // stub, no special data to save                          $block['content'] = _phpbb_display_block_0();
238        return;        break;
239      case 'view':  // fall through  
240      default:        case 1:
241        $block['subject'] = t(variable_get('phpbb_block0_title','phpBB Topics'));                          //Not used
242        $block['content'] = _phpbb_display_block_0();                  break;
243        return $block;      }
244             return $block;
245    }    }
246  }  }
247    
# Line 251  function phpbb_block($op = 'list', $delt Line 249  function phpbb_block($op = 'list', $delt
249   * Implementation of hook_menu().   * Implementation of hook_menu().
250   */   */
251  function phpbb_menu($may_cache) {  function phpbb_menu($may_cache) {
   $items = array();  
   
252    if ($may_cache) {    if ($may_cache) {
253      $items[] = array('path' => 'phpbb', 'title' => t('phpbb'),      $items[] = array(
254          'path' => 'phpbb',
255          'title' => t('phpbb'),
256        'callback' => 'phpbb_view',        'callback' => 'phpbb_view',
257        'access' => TRUE,        'access' => TRUE,
258                  'type' => MENU_SUGGESTED_ITEM);                    'type' => MENU_SUGGESTED_ITEM
259        );
260    
261        $items[] = array(
262          'path' => 'admin/settings/phpbb',
263          'title' => t('phpBB settings'),
264          'description' => t('Configure phpBB integration'),
265          'callback' => 'drupal_get_form',
266          'callback arguments' => array('phpbb_admin_settings'),
267          'access' => user_access('administer site configuration'),
268          'type' => MENU_NORMAL_ITEM,
269        );
270    }    }
271    
272    
273    return $items;    return $items;
274  }  }
275    
276  /**  /**
277   * Menu callback; presents the phpbbsup form and/or phpbbsup results.   * Menu callback; presents the phpbbsup form and/or phpbbsup results.
278     * Doesn't this interfere with hook_view? At least it's confusing
279   */   */
280  function phpbb_view() {  function phpbb_view() {
281          global $user;          global $user;
282    
283          if($user->uid == 0) {          if($user->uid == 0) {
284                  //echo $forum_goto . " " . arg(2);                  //echo $forum_goto . " " . arg(2);
285                  watchdog('user', t('phpBB bounce for %name.', array('%name' => theme('placeholder', $user->name))));                  watchdog('user', t('phpBB bounce for %name.', array('%name' => $user->name)));
286                  session_destroy();                  session_destroy();
287                  $user = user_load(array('uid' => 0));                  $user = user_load(array('uid' => 0));
288                  drupal_goto('user/login?destination=' . variable_get('phpbb_dir', 'phpBB2/') . arg(1));                  drupal_goto('user/login?destination=' . variable_get('phpbb_dir', 'phpBB2/') . arg(1));
289          } else {          } else {
290                  // We know who this is, create session and send them back                  // We know who this is, create session and send them back
291                  watchdog('user', t('phpBB rebuffed %name.', array('%name' => theme('placeholder', $user->name))));                  watchdog('user', t('phpBB rebuffed %name.', array('%name' => $user->name)));
292                  $edit = array();                  $edit = array();
293                  phpbb_user('logout',$edit, $user);                  phpbb_user('logout',$edit, $user);
294                  phpbb_user('login',$edit, $user);                  phpbb_user('login',$edit, $user);
# Line 357  function _phpbb_update_profile_field($ak Line 369  function _phpbb_update_profile_field($ak
369  function _phpbb_get_profile_value($akey) {  function _phpbb_get_profile_value($akey) {
370          // This code does not honor table-prefixes!          // This code does not honor table-prefixes!
371          global $user;          global $user;
372          $result = db_query(     "SELECT profile_values.value AS value FROM profile_values, profile_fields          $result = db_query(     "SELECT {profile_values}.value AS value FROM {profile_values}, {profile_fields}
373                                                                  WHERE profile_fields.fid = profile_values.fid AND profile_fields.name = 'phpbb_".$akey."'                                                                  WHERE {profile_fields}.fid = {profile_values}.fid AND {profile_fields}.name = 'phpbb_%s'
374                                                                  AND profile_values.uid = '".$user->uid."'");                                                                  AND {profile_values}.uid = '%d'",$akey, $user->uid );
375    
376          if (db_num_rows($result) == 1) {          if (db_num_rows($result) == 1) {
377                  $arow = db_fetch_array($result);                  $arow = db_fetch_array($result);

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.18

  ViewVC Help
Powered by ViewVC 1.1.2