Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

user.php

Zuletzt modifiziert: 09.10.2024, 12:51 - Dateigröße: 22.46 KiB


 001  <?php
 002  /**
 003  *
 004  * This file is part of the phpBB Forum Software package.
 005  *
 006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 007  * @license GNU General Public License, version 2 (GPL-2.0)
 008  *
 009  * For full copyright and license information, please see
 010  * the docs/CREDITS.txt file.
 011  *
 012  */
 013   
 014  namespace phpbb;
 015   
 016  /**
 017  * Base user class
 018  *
 019  * This is the overarching class which contains (through session extend)
 020  * all methods utilised for user functionality during a session.
 021  */
 022  class user extends \phpbb\session
 023  {
 024      /**
 025       * @var \phpbb\language\language
 026       */
 027      protected $language;
 028   
 029      var $style = array();
 030      var $date_format;
 031   
 032      /**
 033      * DateTimeZone object holding the timezone of the user
 034      */
 035      public $timezone;
 036   
 037      /**
 038      * @var string Class name of datetime object
 039      */
 040      protected $datetime;
 041   
 042      var $lang_name = false;
 043      var $lang_id = false;
 044      var $lang_path;
 045      var $img_lang;
 046      var $img_array = array();
 047   
 048      /** @var bool */
 049      protected $is_setup_flag;
 050   
 051      // Able to add new options (up to id 31)
 052      var $keyoptions = array('viewimg' => 0, 'viewflash' => 1, 'viewsmilies' => 2, 'viewsigs' => 3, 'viewavatars' => 4, 'viewcensors' => 5, 'attachsig' => 6, 'bbcode' => 8, 'smilies' => 9, 'sig_bbcode' => 15, 'sig_smilies' => 16, 'sig_links' => 17);
 053   
 054      /**
 055      * Constructor to set the lang path
 056      *
 057      * @param \phpbb\language\language    $lang            phpBB's Language loader
 058      * @param string                        $datetime_class    Class name of datetime class
 059      */
 060      function __construct(\phpbb\language\language $lang, $datetime_class)
 061      {
 062          global $phpbb_root_path;
 063   
 064          $this->lang_path = $phpbb_root_path . 'language/';
 065          $this->language = $lang;
 066          $this->datetime = $datetime_class;
 067   
 068          $this->is_setup_flag = false;
 069      }
 070   
 071      /**
 072       * Returns whether user::setup was called
 073       *
 074       * @return bool
 075       */
 076      public function is_setup()
 077      {
 078          return $this->is_setup_flag;
 079      }
 080   
 081      /**
 082       * Magic getter for BC compatibility
 083       *
 084       * Implement array access for user::lang.
 085       *
 086       * @param string    $param_name    Name of the BC component the user want to access
 087       *
 088       * @return array    The appropriate array
 089       *
 090       * @deprecated 3.2.0-dev (To be removed: 4.0.0)
 091       */
 092      public function __get($param_name)
 093      {
 094          if ($param_name === 'lang')
 095          {
 096              return $this->language->get_lang_array();
 097          }
 098          else if ($param_name === 'help')
 099          {
 100              $help_array = $this->language->get_lang_array();
 101              return $help_array['__help'];
 102          }
 103   
 104          return array();
 105      }
 106   
 107      /**
 108      * Setup basic user-specific items (style, language, ...)
 109      */
 110      function setup($lang_set = false, $style_id = false)
 111      {
 112          global $db, $request, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache;
 113          global $phpbb_dispatcher;
 114   
 115          $this->language->set_default_language($config['default_lang']);
 116   
 117          if ($this->data['user_id'] != ANONYMOUS)
 118          {
 119              $user_lang_name = (file_exists($this->lang_path . $this->data['user_lang'] . "/common.$phpEx")) ? $this->data['user_lang'] : basename($config['default_lang']);
 120              $user_date_format = $this->data['user_dateformat'];
 121              $user_timezone = $this->data['user_timezone'];
 122          }
 123          else
 124          {
 125              $lang_override = $request->variable('language', '');
 126              if ($lang_override)
 127              {
 128                  $this->set_cookie('lang', $lang_override, 0, false);
 129              }
 130              else
 131              {
 132                  $lang_override = $request->variable($config['cookie_name'] . '_lang', '', true, \phpbb\request\request_interface::COOKIE);
 133              }
 134   
 135              if ($lang_override)
 136              {
 137                  $use_lang = basename($lang_override);
 138                  $user_lang_name = (file_exists($this->lang_path . $use_lang . "/common.$phpEx")) ? $use_lang : basename($config['default_lang']);
 139                  $this->data['user_lang'] = $user_lang_name;
 140              }
 141              else
 142              {
 143                  $user_lang_name = basename($config['default_lang']);
 144              }
 145   
 146              $user_date_format = $config['default_dateformat'];
 147              $user_timezone = $config['board_timezone'];
 148   
 149              /**
 150              * If a guest user is surfing, we try to guess his/her language first by obtaining the browser language
 151              * If re-enabled we need to make sure only those languages installed are checked
 152              * Commented out so we do not loose the code.
 153   
 154              if ($request->header('Accept-Language'))
 155              {
 156                  $accept_lang_ary = explode(',', $request->header('Accept-Language'));
 157   
 158                  foreach ($accept_lang_ary as $accept_lang)
 159                  {
 160                      // Set correct format ... guess full xx_YY form
 161                      $accept_lang = substr($accept_lang, 0, 2) . '_' . strtoupper(substr($accept_lang, 3, 2));
 162                      $accept_lang = basename($accept_lang);
 163   
 164                      if (file_exists($this->lang_path . $accept_lang . "/common.$phpEx"))
 165                      {
 166                          $user_lang_name = $config['default_lang'] = $accept_lang;
 167                          break;
 168                      }
 169                      else
 170                      {
 171                          // No match on xx_YY so try xx
 172                          $accept_lang = substr($accept_lang, 0, 2);
 173                          $accept_lang = basename($accept_lang);
 174   
 175                          if (file_exists($this->lang_path . $accept_lang . "/common.$phpEx"))
 176                          {
 177                              $user_lang_name = $config['default_lang'] = $accept_lang;
 178                              break;
 179                          }
 180                      }
 181                  }
 182              }
 183              */
 184          }
 185   
 186          $user_data = $this->data;
 187          $lang_set_ext = array();
 188   
 189          /**
 190          * Event to load language files and modify user data on every page
 191          *
 192          * @event core.user_setup
 193          * @var    array    user_data            Array with user's data row
 194          * @var    string    user_lang_name        Basename of the user's langauge
 195          * @var    string    user_date_format    User's date/time format
 196          * @var    string    user_timezone        User's timezone, should be one of
 197          *                            http://www.php.net/manual/en/timezones.php
 198          * @var    mixed    lang_set            String or array of language files
 199          * @var    array    lang_set_ext        Array containing entries of format
 200          *                     array(
 201          *                         'ext_name' => (string) [extension name],
 202          *                         'lang_set' => (string|array) [language files],
 203          *                     )
 204          *                     For performance reasons, only load translations
 205          *                     that are absolutely needed globally using this
 206          *                     event. Use local events otherwise.
 207          * @var    mixed    style_id            Style we are going to display
 208          * @since 3.1.0-a1
 209          */
 210          $vars = array(
 211              'user_data',
 212              'user_lang_name',
 213              'user_date_format',
 214              'user_timezone',
 215              'lang_set',
 216              'lang_set_ext',
 217              'style_id',
 218          );
 219          extract($phpbb_dispatcher->trigger_event('core.user_setup', compact($vars)));
 220   
 221          $this->data = $user_data;
 222          $this->lang_name = $user_lang_name;
 223          $this->date_format = $user_date_format;
 224   
 225          $this->language->set_user_language($user_lang_name);
 226   
 227          try
 228          {
 229              $this->timezone = new \DateTimeZone($user_timezone);
 230          }
 231          catch (\Exception $e)
 232          {
 233              // If the timezone the user has selected is invalid, we fall back to UTC.
 234              $this->timezone = new \DateTimeZone('UTC');
 235          }
 236   
 237          $this->add_lang($lang_set);
 238          unset($lang_set);
 239   
 240          foreach ($lang_set_ext as $ext_lang_pair)
 241          {
 242              $this->add_lang_ext($ext_lang_pair['ext_name'], $ext_lang_pair['lang_set']);
 243          }
 244          unset($lang_set_ext);
 245   
 246          $style_request = $request->variable('style', 0);
 247          if ($style_request && (!$config['override_user_style'] || $auth->acl_get('a_styles')) && !defined('ADMIN_START'))
 248          {
 249              global $SID, $_EXTRA_URL;
 250   
 251              $style_id = $style_request;
 252              $SID .= '&amp;style=' . $style_id;
 253              $_EXTRA_URL = array('style=' . $style_id);
 254          }
 255          else
 256          {
 257              // Set up style
 258              $style_id = ($style_id) ? $style_id : ((!$config['override_user_style']) ? $this->data['user_style'] : $config['default_style']);
 259          }
 260   
 261          $sql = 'SELECT *
 262              FROM ' . STYLES_TABLE . " s
 263              WHERE s.style_id = $style_id";
 264          $result = $db->sql_query($sql, 3600);
 265          $this->style = $db->sql_fetchrow($result);
 266          $db->sql_freeresult($result);
 267   
 268          // Fallback to user's standard style
 269          if (!$this->style && $style_id != $this->data['user_style'])
 270          {
 271              $style_id = $this->data['user_style'];
 272   
 273              $sql = 'SELECT *
 274                  FROM ' . STYLES_TABLE . " s
 275                  WHERE s.style_id = $style_id";
 276              $result = $db->sql_query($sql, 3600);
 277              $this->style = $db->sql_fetchrow($result);
 278              $db->sql_freeresult($result);
 279          }
 280   
 281          // User has wrong style
 282          if (!$this->style && $style_id == $this->data['user_style'])
 283          {
 284              $style_id = $this->data['user_style'] = $config['default_style'];
 285   
 286              $sql = 'UPDATE ' . USERS_TABLE . "
 287                  SET user_style = $style_id
 288                  WHERE user_id = {$this->data['user_id']}";
 289              $db->sql_query($sql);
 290   
 291              $sql = 'SELECT *
 292                  FROM ' . STYLES_TABLE . " s
 293                  WHERE s.style_id = $style_id";
 294              $result = $db->sql_query($sql, 3600);
 295              $this->style = $db->sql_fetchrow($result);
 296              $db->sql_freeresult($result);
 297          }
 298   
 299          if (!$this->style)
 300          {
 301              trigger_error('NO_STYLE_DATA', E_USER_ERROR);
 302          }
 303   
 304          // Now parse the cfg file and cache it
 305          $parsed_items = $cache->obtain_cfg_items($this->style);
 306   
 307          $check_for = array(
 308              'pagination_sep'    => (string) ', '
 309          );
 310   
 311          foreach ($check_for as $key => $default_value)
 312          {
 313              $this->style[$key] = (isset($parsed_items[$key])) ? $parsed_items[$key] : $default_value;
 314              settype($this->style[$key], gettype($default_value));
 315   
 316              if (is_string($default_value))
 317              {
 318                  $this->style[$key] = htmlspecialchars($this->style[$key]);
 319              }
 320          }
 321   
 322          $template->set_style();
 323   
 324          $this->img_lang = $this->lang_name;
 325   
 326          // Call phpbb_user_session_handler() in case external application want to "bend" some variables or replace classes...
 327          // After calling it we continue script execution...
 328          phpbb_user_session_handler();
 329   
 330          /**
 331          * Execute code at the end of user setup
 332          *
 333          * @event core.user_setup_after
 334          * @since 3.1.6-RC1
 335          */
 336          $phpbb_dispatcher->dispatch('core.user_setup_after');
 337   
 338          // If this function got called from the error handler we are finished here.
 339          if (defined('IN_ERROR_HANDLER'))
 340          {
 341              return;
 342          }
 343   
 344          // Disable board if the install/ directory is still present
 345          // For the brave development army we do not care about this, else we need to comment out this everytime we develop locally
 346          if (!defined('DEBUG') && !defined('ADMIN_START') && !defined('IN_INSTALL') && !defined('IN_LOGIN') && file_exists($phpbb_root_path . 'install') && !is_file($phpbb_root_path . 'install'))
 347          {
 348              // Adjust the message slightly according to the permissions
 349              if ($auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'))
 350              {
 351                  $message = 'REMOVE_INSTALL';
 352              }
 353              else
 354              {
 355                  $message = (!empty($config['board_disable_msg'])) ? $config['board_disable_msg'] : 'BOARD_DISABLE';
 356              }
 357              trigger_error($message);
 358          }
 359   
 360          // Is board disabled and user not an admin or moderator?
 361          if ($config['board_disable'] && !defined('IN_LOGIN') && !defined('SKIP_CHECK_DISABLED') && !$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
 362          {
 363              if ($this->data['is_bot'])
 364              {
 365                  send_status_line(503, 'Service Unavailable');
 366              }
 367   
 368              $message = (!empty($config['board_disable_msg'])) ? $config['board_disable_msg'] : 'BOARD_DISABLE';
 369              trigger_error($message);
 370          }
 371   
 372          // Is load exceeded?
 373          if ($config['limit_load'] && $this->load !== false)
 374          {
 375              if ($this->load > floatval($config['limit_load']) && !defined('IN_LOGIN') && !defined('IN_ADMIN'))
 376              {
 377                  // Set board disabled to true to let the admins/mods get the proper notification
 378                  $config['board_disable'] = '1';
 379   
 380                  if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
 381                  {
 382                      if ($this->data['is_bot'])
 383                      {
 384                          send_status_line(503, 'Service Unavailable');
 385                      }
 386                      trigger_error('BOARD_UNAVAILABLE');
 387                  }
 388              }
 389          }
 390   
 391          if (isset($this->data['session_viewonline']))
 392          {
 393              // Make sure the user is able to hide his session
 394              if (!$this->data['session_viewonline'])
 395              {
 396                  // Reset online status if not allowed to hide the session...
 397                  if (!$auth->acl_get('u_hideonline'))
 398                  {
 399                      $sql = 'UPDATE ' . SESSIONS_TABLE . '
 400                          SET session_viewonline = 1
 401                          WHERE session_user_id = ' . $this->data['user_id'];
 402                      $db->sql_query($sql);
 403                      $this->data['session_viewonline'] = 1;
 404                  }
 405              }
 406              else if (!$this->data['user_allow_viewonline'])
 407              {
 408                  // the user wants to hide and is allowed to  -> cloaking device on.
 409                  if ($auth->acl_get('u_hideonline'))
 410                  {
 411                      $sql = 'UPDATE ' . SESSIONS_TABLE . '
 412                          SET session_viewonline = 0
 413                          WHERE session_user_id = ' . $this->data['user_id'];
 414                      $db->sql_query($sql);
 415                      $this->data['session_viewonline'] = 0;
 416                  }
 417              }
 418          }
 419   
 420          // Does the user need to change their password? If so, redirect to the
 421          // ucp profile reg_details page ... of course do not redirect if we're already in the ucp
 422          if (!defined('IN_ADMIN') && !defined('ADMIN_START') && $config['chg_passforce'] && !empty($this->data['is_registered']) && $auth->acl_get('u_chgpasswd') && $this->data['user_passchg'] < time() - ($config['chg_passforce'] * 86400))
 423          {
 424              if (strpos($this->page['query_string'], 'mode=reg_details') === false && $this->page['page_name'] != "ucp.$phpEx")
 425              {
 426                  redirect(append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=profile&amp;mode=reg_details'));
 427              }
 428          }
 429   
 430          $this->is_setup_flag = true;
 431   
 432          return;
 433      }
 434   
 435      /**
 436      * More advanced language substitution
 437      * Function to mimic sprintf() with the possibility of using phpBB's language system to substitute nullar/singular/plural forms.
 438      * Params are the language key and the parameters to be substituted.
 439      * This function/functionality is inspired by SHS` and Ashe.
 440      *
 441      * Example call: <samp>$user->lang('NUM_POSTS_IN_QUEUE', 1);</samp>
 442      *
 443      * If the first parameter is an array, the elements are used as keys and subkeys to get the language entry:
 444      * Example: <samp>$user->lang(array('datetime', 'AGO'), 1)</samp> uses $user->lang['datetime']['AGO'] as language entry.
 445      *
 446      * @deprecated 3.2.0-dev (To be removed 4.0.0)
 447      */
 448      function lang()
 449      {
 450          $args = func_get_args();
 451          return call_user_func_array(array($this->language, 'lang'), $args);
 452      }
 453   
 454      /**
 455      * Determine which plural form we should use.
 456      * For some languages this is not as simple as for English.
 457      *
 458      * @param $number        int|float   The number we want to get the plural case for. Float numbers are floored.
 459      * @param $force_rule    mixed   False to use the plural rule of the language package
 460      *                               or an integer to force a certain plural rule
 461      * @return int|bool     The plural-case we need to use for the number plural-rule combination, false if $force_rule
 462      *                        was invalid.
 463      *
 464      * @deprecated: 3.2.0-dev (To be removed: 3.3.0)
 465      */
 466      function get_plural_form($number, $force_rule = false)
 467      {
 468          return $this->language->get_plural_form($number, $force_rule);
 469      }
 470   
 471      /**
 472      * Add Language Items - use_db and use_help are assigned where needed (only use them to force inclusion)
 473      *
 474      * @param mixed $lang_set specifies the language entries to include
 475      * @param bool $use_db internal variable for recursion, do not use    @deprecated 3.2.0-dev (To be removed: 3.3.0)
 476      * @param bool $use_help internal variable for recursion, do not use    @deprecated 3.2.0-dev (To be removed: 3.3.0)
 477      * @param string $ext_name The extension to load language from, or empty for core files
 478      *
 479      * Examples:
 480      * <code>
 481      * $lang_set = array('posting', 'help' => 'faq');
 482      * $lang_set = array('posting', 'viewtopic', 'help' => array('bbcode', 'faq'))
 483      * $lang_set = array(array('posting', 'viewtopic'), 'help' => array('bbcode', 'faq'))
 484      * $lang_set = 'posting'
 485      * $lang_set = array('help' => 'faq', 'db' => array('help:faq', 'posting'))
 486      * </code>
 487      *
 488      * Note: $use_db and $use_help should be removed. The old function was kept for BC purposes,
 489      *         so the BC logic is handled here.
 490      *
 491      * @deprecated: 3.2.0-dev (To be removed: 3.3.0)
 492      */
 493      function add_lang($lang_set, $use_db = false, $use_help = false, $ext_name = '')
 494      {
 495          if (is_array($lang_set))
 496          {
 497              foreach ($lang_set as $key => $lang_file)
 498              {
 499                  // Please do not delete this line.
 500                  // We have to force the type here, else [array] language inclusion will not work
 501                  $key = (string) $key;
 502   
 503                  if ($key == 'db')
 504                  {
 505                      // This is never used
 506                      $this->add_lang($lang_file, true, $use_help, $ext_name);
 507                  }
 508                  else if ($key == 'help')
 509                  {
 510                      $this->add_lang($lang_file, $use_db, true, $ext_name);
 511                  }
 512                  else if (!is_array($lang_file))
 513                  {
 514                      $this->set_lang($lang_file, $use_help, $ext_name);
 515                  }
 516                  else
 517                  {
 518                      $this->add_lang($lang_file, $use_db, $use_help, $ext_name);
 519                  }
 520              }
 521              unset($lang_set);
 522          }
 523          else if ($lang_set)
 524          {
 525              $this->set_lang($lang_set, $use_help, $ext_name);
 526          }
 527      }
 528   
 529      /**
 530       * BC function for loading language files
 531       *
 532       * @deprecated 3.2.0-dev (To be removed: 3.3.0)
 533       */
 534      private function set_lang($lang_set, $use_help, $ext_name)
 535      {
 536          if (empty($ext_name))
 537          {
 538              $ext_name = null;
 539          }
 540   
 541          if ($use_help && strpos($lang_set, '/') !== false)
 542          {
 543              $component = dirname($lang_set) . '/help_' . basename($lang_set);
 544   
 545              if ($component[0] === '/')
 546              {
 547                  $component = substr($component, 1);
 548              }
 549          }
 550          else
 551          {
 552              $component = (($use_help) ? 'help_' : '') . $lang_set;
 553          }
 554   
 555          $this->language->add_lang($component, $ext_name);
 556      }
 557   
 558      /**
 559      * Add Language Items from an extension - use_db and use_help are assigned where needed (only use them to force inclusion)
 560      *
 561      * @param string $ext_name The extension to load language from, or empty for core files
 562      * @param mixed $lang_set specifies the language entries to include
 563      * @param bool $use_db internal variable for recursion, do not use
 564      * @param bool $use_help internal variable for recursion, do not use
 565      *
 566      * Note: $use_db and $use_help should be removed. Kept for BC purposes.
 567      *
 568      * @deprecated: 3.2.0-dev (To be removed: 3.3.0)
 569      */
 570      function add_lang_ext($ext_name, $lang_set, $use_db = false, $use_help = false)
 571      {
 572          if ($ext_name === '/')
 573          {
 574              $ext_name = '';
 575          }
 576   
 577          $this->add_lang($lang_set, $use_db, $use_help, $ext_name);
 578      }
 579   
 580      /**
 581      * Format user date
 582      *
 583      * @param int $gmepoch unix timestamp
 584      * @param string $format date format in date() notation. | used to indicate relative dates, for example |d m Y|, h:i is translated to Today, h:i.
 585      * @param bool $forcedate force non-relative date format.
 586      *
 587      * @return mixed translated date
 588      */
 589      function format_date($gmepoch, $format = false, $forcedate = false)
 590      {
 591          static $utc;
 592   
 593          if (!isset($utc))
 594          {
 595              $utc = new \DateTimeZone('UTC');
 596          }
 597   
 598          $time = new $this->datetime($this, '@' . (int) $gmepoch, $utc);
 599          $time->setTimezone($this->timezone);
 600   
 601          return $time->format($format, $forcedate);
 602      }
 603   
 604      /**
 605      * Create a \phpbb\datetime object in the context of the current user
 606      *
 607      * @since 3.1
 608      * @param string $time String in a format accepted by strtotime().
 609      * @param DateTimeZone $timezone Time zone of the time.
 610      * @return \phpbb\datetime Date time object linked to the current users locale
 611      */
 612      public function create_datetime($time = 'now', \DateTimeZone $timezone = null)
 613      {
 614          $timezone = $timezone ?: $this->timezone;
 615          return new $this->datetime($this, $time, $timezone);
 616      }
 617   
 618      /**
 619      * Get the UNIX timestamp for a datetime in the users timezone, so we can store it in the database.
 620      *
 621      * @param    string            $format        Format of the entered date/time
 622      * @param    string            $time        Date/time with the timezone applied
 623      * @param    DateTimeZone    $timezone    Timezone of the date/time, falls back to timezone of current user
 624      * @return    int            Returns the unix timestamp
 625      */
 626      public function get_timestamp_from_format($format, $time, \DateTimeZone $timezone = null)
 627      {
 628          $timezone = $timezone ?: $this->timezone;
 629          $date = \DateTime::createFromFormat($format, $time, $timezone);
 630          return ($date !== false) ? $date->format('U') : false;
 631      }
 632   
 633      /**
 634      * Get language id currently used by the user
 635      */
 636      function get_iso_lang_id()
 637      {
 638          global $config, $db;
 639   
 640          if (!empty($this->lang_id))
 641          {
 642              return $this->lang_id;
 643          }
 644   
 645          if (!$this->lang_name)
 646          {
 647              $this->lang_name = $config['default_lang'];
 648          }
 649   
 650          $sql = 'SELECT lang_id
 651              FROM ' . LANG_TABLE . "
 652              WHERE lang_iso = '" . $db->sql_escape($this->lang_name) . "'";
 653          $result = $db->sql_query($sql);
 654          $this->lang_id = (int) $db->sql_fetchfield('lang_id');
 655          $db->sql_freeresult($result);
 656   
 657          return $this->lang_id;
 658      }
 659   
 660      /**
 661      * Get users profile fields
 662      */
 663      function get_profile_fields($user_id)
 664      {
 665          global $db;
 666   
 667          if (isset($this->profile_fields))
 668          {
 669              return;
 670          }
 671   
 672          $sql = 'SELECT *
 673              FROM ' . PROFILE_FIELDS_DATA_TABLE . "
 674              WHERE user_id = $user_id";
 675          $result = $db->sql_query_limit($sql, 1);
 676          $this->profile_fields = (!($row = $db->sql_fetchrow($result))) ? array() : $row;
 677          $db->sql_freeresult($result);
 678      }
 679   
 680      /**
 681      * Specify/Get image
 682      */
 683      function img($img, $alt = '')
 684      {
 685          $title = '';
 686   
 687          if ($alt)
 688          {
 689              $alt = $this->language->lang($alt);
 690              $title = ' title="' . $alt . '"';
 691          }
 692          return '<span class="imageset ' . $img . '"' . $title . '>' . $alt . '</span>';
 693      }
 694   
 695      /**
 696      * Get option bit field from user options.
 697      *
 698      * @param int $key option key, as defined in $keyoptions property.
 699      * @param int $data bit field value to use, or false to use $this->data['user_options']
 700      * @return bool true if the option is set in the bit field, false otherwise
 701      */
 702      function optionget($key, $data = false)
 703      {
 704          $var = ($data !== false) ? $data : $this->data['user_options'];
 705          return phpbb_optionget($this->keyoptions[$key], $var);
 706      }
 707   
 708      /**
 709      * Set option bit field for user options.
 710      *
 711      * @param int $key Option key, as defined in $keyoptions property.
 712      * @param bool $value True to set the option, false to clear the option.
 713      * @param int $data Current bit field value, or false to use $this->data['user_options']
 714      * @return int|bool If $data is false, the bit field is modified and
 715      *                  written back to $this->data['user_options'], and
 716      *                  return value is true if the bit field changed and
 717      *                  false otherwise. If $data is not false, the new
 718      *                  bitfield value is returned.
 719      */
 720      function optionset($key, $value, $data = false)
 721      {
 722          $var = ($data !== false) ? $data : $this->data['user_options'];
 723   
 724          $new_var = phpbb_optionset($this->keyoptions[$key], $value, $var);
 725   
 726          if ($data === false)
 727          {
 728              if ($new_var != $var)
 729              {
 730                  $this->data['user_options'] = $new_var;
 731                  return true;
 732              }
 733              else
 734              {
 735                  return false;
 736              }
 737          }
 738          else
 739          {
 740              return $new_var;
 741          }
 742      }
 743   
 744      /**
 745      * Funtion to make the user leave the NEWLY_REGISTERED system group.
 746      * @access public
 747      */
 748      function leave_newly_registered()
 749      {
 750          if (empty($this->data['user_new']))
 751          {
 752              return false;
 753          }
 754   
 755          if (!function_exists('remove_newly_registered'))
 756          {
 757              global $phpbb_root_path, $phpEx;
 758   
 759              include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
 760          }
 761          if ($group = remove_newly_registered($this->data['user_id'], $this->data))
 762          {
 763              $this->data['group_id'] = $group;
 764   
 765          }
 766          $this->data['user_permissions'] = '';
 767          $this->data['user_new'] = 0;
 768   
 769          return true;
 770      }
 771   
 772      /**
 773      * Returns all password protected forum ids the user is currently NOT authenticated for.
 774      *
 775      * @return array     Array of forum ids
 776      * @access public
 777      */
 778      function get_passworded_forums()
 779      {
 780          global $db;
 781   
 782          $sql = 'SELECT f.forum_id, fa.user_id
 783              FROM ' . FORUMS_TABLE . ' f
 784              LEFT JOIN ' . FORUMS_ACCESS_TABLE . " fa
 785                  ON (fa.forum_id = f.forum_id
 786                      AND fa.session_id = '" . $db->sql_escape($this->session_id) . "')
 787              WHERE f.forum_password <> ''";
 788          $result = $db->sql_query($sql);
 789   
 790          $forum_ids = array();
 791          while ($row = $db->sql_fetchrow($result))
 792          {
 793              $forum_id = (int) $row['forum_id'];
 794   
 795              if ($row['user_id'] != $this->data['user_id'])
 796              {
 797                  $forum_ids[$forum_id] = $forum_id;
 798              }
 799          }
 800          $db->sql_freeresult($result);
 801   
 802          return $forum_ids;
 803      }
 804  }
 805