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

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

  ViewVC Help
Powered by ViewVC 1.1.2