[ Index ]

PHP Cross Reference of phpBB-3.2.8-deutsch

title

Body

[close]

/phpbb/ -> user.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  namespace phpbb;
  15  
  16  /**
  17  * Base user class
  18  *
  19  * This is the overarching class which contains (through session extend)
  20  * all methods utilised for user functionality during a session.
  21  */
  22  class user extends \phpbb\session
  23  {
  24      /**
  25       * @var \phpbb\language\language
  26       */
  27      protected $language;
  28  
  29      var $style = array();
  30      var $date_format;
  31  
  32      /**
  33      * DateTimeZone object holding the timezone of the user
  34      */
  35      public $timezone;
  36  
  37      /**
  38      * @var string Class name of datetime object
  39      */
  40      protected $datetime;
  41  
  42      var $lang_name = false;
  43      var $lang_id = false;
  44      var $lang_path;
  45      var $img_lang;
  46      var $img_array = array();
  47  
  48      /** @var bool */
  49      protected $is_setup_flag;
  50  
  51      // Able to add new options (up to id 31)
  52      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);
  53  
  54      /**
  55      * Constructor to set the lang path
  56      *
  57      * @param \phpbb\language\language    $lang            phpBB's Language loader
  58      * @param string                        $datetime_class    Class name of datetime class
  59      */
  60  	function __construct(\phpbb\language\language $lang, $datetime_class)
  61      {
  62          global $phpbb_root_path;
  63  
  64          $this->lang_path = $phpbb_root_path . 'language/';
  65          $this->language = $lang;
  66          $this->datetime = $datetime_class;
  67  
  68          $this->is_setup_flag = false;
  69      }
  70  
  71      /**
  72       * Returns whether user::setup was called
  73       *
  74       * @return bool
  75       */
  76  	public function is_setup()
  77      {
  78          return $this->is_setup_flag;
  79      }
  80  
  81      /**
  82       * Magic getter for BC compatibility
  83       *
  84       * Implement array access for user::lang.
  85       *
  86       * @param string    $param_name    Name of the BC component the user want to access
  87       *
  88       * @return array    The appropriate array
  89       *
  90       * @deprecated 3.2.0-dev (To be removed: 4.0.0)
  91       */
  92  	public function __get($param_name)
  93      {
  94          if ($param_name === 'lang')
  95          {
  96              return $this->language->get_lang_array();
  97          }
  98          else if ($param_name === 'help')
  99          {
 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          * Note: To load language file with this event, see description
 193          * of lang_set_ext variable.
 194          *
 195          * @event core.user_setup
 196          * @var    array    user_data            Array with user's data row
 197          * @var    string    user_lang_name        Basename of the user's langauge
 198          * @var    string    user_date_format    User's date/time format
 199          * @var    string    user_timezone        User's timezone, should be one of
 200          *                            http://www.php.net/manual/en/timezones.php
 201          * @var    mixed    lang_set            String or array of language files
 202          * @var    array    lang_set_ext        Array containing entries of format
 203          *                     array(
 204          *                         'ext_name' => (string) [extension name],
 205          *                         'lang_set' => (string|array) [language files],
 206          *                     )
 207          *                     For performance reasons, only load translations
 208          *                     that are absolutely needed globally using this
 209          *                     event. Use local events otherwise.
 210          * @var    mixed    style_id            Style we are going to display
 211          * @since 3.1.0-a1
 212          */
 213          $vars = array(
 214              'user_data',
 215              'user_lang_name',
 216              'user_date_format',
 217              'user_timezone',
 218              'lang_set',
 219              'lang_set_ext',
 220              'style_id',
 221          );
 222          extract($phpbb_dispatcher->trigger_event('core.user_setup', compact($vars)));
 223  
 224          $this->data = $user_data;
 225          $this->lang_name = $user_lang_name;
 226          $this->date_format = $user_date_format;
 227  
 228          $this->language->set_user_language($user_lang_name);
 229  
 230          try
 231          {
 232              $this->timezone = new \DateTimeZone($user_timezone);
 233          }
 234          catch (\Exception $e)
 235          {
 236              // If the timezone the user has selected is invalid, we fall back to UTC.
 237              $this->timezone = new \DateTimeZone('UTC');
 238          }
 239  
 240          $this->add_lang($lang_set);
 241          unset($lang_set);
 242  
 243          foreach ($lang_set_ext as $ext_lang_pair)
 244          {
 245              $this->add_lang_ext($ext_lang_pair['ext_name'], $ext_lang_pair['lang_set']);
 246          }
 247          unset($lang_set_ext);
 248  
 249          $style_request = $request->variable('style', 0);
 250          if ($style_request && (!$config['override_user_style'] || $auth->acl_get('a_styles')) && !defined('ADMIN_START'))
 251          {
 252              global $SID, $_EXTRA_URL;
 253  
 254              $style_id = $style_request;
 255              $SID .= '&amp;style=' . $style_id;
 256              $_EXTRA_URL = array('style=' . $style_id);
 257          }
 258          else
 259          {
 260              // Set up style
 261              $style_id = ($style_id) ? $style_id : ((!$config['override_user_style']) ? $this->data['user_style'] : $config['default_style']);
 262          }
 263  
 264          $sql = 'SELECT *
 265              FROM ' . STYLES_TABLE . " s
 266              WHERE s.style_id = $style_id";
 267          $result = $db->sql_query($sql, 3600);
 268          $this->style = $db->sql_fetchrow($result);
 269          $db->sql_freeresult($result);
 270  
 271          // Fallback to user's standard style
 272          if (!$this->style && $style_id != $this->data['user_style'])
 273          {
 274              $style_id = $this->data['user_style'];
 275  
 276              $sql = 'SELECT *
 277                  FROM ' . STYLES_TABLE . " s
 278                  WHERE s.style_id = $style_id";
 279              $result = $db->sql_query($sql, 3600);
 280              $this->style = $db->sql_fetchrow($result);
 281              $db->sql_freeresult($result);
 282          }
 283  
 284          if (!$this->style)
 285          {
 286              trigger_error('NO_STYLE_DATA', E_USER_ERROR);
 287          }
 288  
 289          // Now parse the cfg file and cache it
 290          $parsed_items = $cache->obtain_cfg_items($this->style);
 291  
 292          $check_for = array(
 293              'pagination_sep'    => (string) ', '
 294          );
 295  
 296          foreach ($check_for as $key => $default_value)
 297          {
 298              $this->style[$key] = (isset($parsed_items[$key])) ? $parsed_items[$key] : $default_value;
 299              settype($this->style[$key], gettype($default_value));
 300  
 301              if (is_string($default_value))
 302              {
 303                  $this->style[$key] = htmlspecialchars($this->style[$key]);
 304              }
 305          }
 306  
 307          $template->set_style();
 308  
 309          $this->img_lang = $this->lang_name;
 310  
 311          // Call phpbb_user_session_handler() in case external application want to "bend" some variables or replace classes...
 312          // After calling it we continue script execution...
 313          phpbb_user_session_handler();
 314  
 315          /**
 316          * Execute code at the end of user setup
 317          *
 318          * @event core.user_setup_after
 319          * @since 3.1.6-RC1
 320          */
 321          $phpbb_dispatcher->dispatch('core.user_setup_after');
 322  
 323          // If this function got called from the error handler we are finished here.
 324          if (defined('IN_ERROR_HANDLER'))
 325          {
 326              return;
 327          }
 328  
 329          // Disable board if the install/ directory is still present
 330          // For the brave development army we do not care about this, else we need to comment out this everytime we develop locally
 331          if (!defined('DEBUG') && !defined('ADMIN_START') && !defined('IN_INSTALL') && !defined('IN_LOGIN') && file_exists($phpbb_root_path . 'install') && !is_file($phpbb_root_path . 'install'))
 332          {
 333              // Adjust the message slightly according to the permissions
 334              if ($auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'))
 335              {
 336                  $message = 'REMOVE_INSTALL';
 337              }
 338              else
 339              {
 340                  $message = (!empty($config['board_disable_msg'])) ? $config['board_disable_msg'] : 'BOARD_DISABLE';
 341              }
 342              trigger_error($message);
 343          }
 344  
 345          // Is board disabled and user not an admin or moderator?
 346          if ($config['board_disable'] && !defined('IN_INSTALL') && !defined('IN_LOGIN') && !defined('SKIP_CHECK_DISABLED') && !$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
 347          {
 348              if ($this->data['is_bot'])
 349              {
 350                  send_status_line(503, 'Service Unavailable');
 351              }
 352  
 353              $message = (!empty($config['board_disable_msg'])) ? $config['board_disable_msg'] : 'BOARD_DISABLE';
 354              trigger_error($message);
 355          }
 356  
 357          // Is load exceeded?
 358          if ($config['limit_load'] && $this->load !== false)
 359          {
 360              if ($this->load > floatval($config['limit_load']) && !defined('IN_LOGIN') && !defined('IN_ADMIN'))
 361              {
 362                  // Set board disabled to true to let the admins/mods get the proper notification
 363                  $config['board_disable'] = '1';
 364  
 365                  if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
 366                  {
 367                      if ($this->data['is_bot'])
 368                      {
 369                          send_status_line(503, 'Service Unavailable');
 370                      }
 371                      trigger_error('BOARD_UNAVAILABLE');
 372                  }
 373              }
 374          }
 375  
 376          if (isset($this->data['session_viewonline']))
 377          {
 378              // Make sure the user is able to hide his session
 379              if (!$this->data['session_viewonline'])
 380              {
 381                  // Reset online status if not allowed to hide the session...
 382                  if (!$auth->acl_get('u_hideonline'))
 383                  {
 384                      $sql = 'UPDATE ' . SESSIONS_TABLE . '
 385                          SET session_viewonline = 1
 386                          WHERE session_user_id = ' . $this->data['user_id'];
 387                      $db->sql_query($sql);
 388                      $this->data['session_viewonline'] = 1;
 389                  }
 390              }
 391              else if (!$this->data['user_allow_viewonline'])
 392              {
 393                  // the user wants to hide and is allowed to  -> cloaking device on.
 394                  if ($auth->acl_get('u_hideonline'))
 395                  {
 396                      $sql = 'UPDATE ' . SESSIONS_TABLE . '
 397                          SET session_viewonline = 0
 398                          WHERE session_user_id = ' . $this->data['user_id'];
 399                      $db->sql_query($sql);
 400                      $this->data['session_viewonline'] = 0;
 401                  }
 402              }
 403          }
 404  
 405          // Does the user need to change their password? If so, redirect to the
 406          // ucp profile reg_details page ... of course do not redirect if we're already in the ucp
 407          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))
 408          {
 409              if (strpos($this->page['query_string'], 'mode=reg_details') === false && $this->page['page_name'] != "ucp.$phpEx")
 410              {
 411                  redirect(append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=profile&amp;mode=reg_details'));
 412              }
 413          }
 414  
 415          $this->is_setup_flag = true;
 416  
 417          return;
 418      }
 419  
 420      /**
 421      * More advanced language substitution
 422      * Function to mimic sprintf() with the possibility of using phpBB's language system to substitute nullar/singular/plural forms.
 423      * Params are the language key and the parameters to be substituted.
 424      * This function/functionality is inspired by SHS` and Ashe.
 425      *
 426      * Example call: <samp>$user->lang('NUM_POSTS_IN_QUEUE', 1);</samp>
 427      *
 428      * If the first parameter is an array, the elements are used as keys and subkeys to get the language entry:
 429      * Example: <samp>$user->lang(array('datetime', 'AGO'), 1)</samp> uses $user->lang['datetime']['AGO'] as language entry.
 430      *
 431      * @deprecated 3.2.0-dev (To be removed 4.0.0)
 432      */
 433  	function lang()
 434      {
 435          $args = func_get_args();
 436          return call_user_func_array(array($this->language, 'lang'), $args);
 437      }
 438  
 439      /**
 440      * Determine which plural form we should use.
 441      * For some languages this is not as simple as for English.
 442      *
 443      * @param $number        int|float   The number we want to get the plural case for. Float numbers are floored.
 444      * @param $force_rule    mixed   False to use the plural rule of the language package
 445      *                               or an integer to force a certain plural rule
 446      * @return int|bool     The plural-case we need to use for the number plural-rule combination, false if $force_rule
 447      *                        was invalid.
 448      *
 449      * @deprecated: 3.2.0-dev (To be removed: 3.3.0)
 450      */
 451  	function get_plural_form($number, $force_rule = false)
 452      {
 453          return $this->language->get_plural_form($number, $force_rule);
 454      }
 455  
 456      /**
 457      * Add Language Items - use_db and use_help are assigned where needed (only use them to force inclusion)
 458      *
 459      * @param mixed $lang_set specifies the language entries to include
 460      * @param bool $use_db internal variable for recursion, do not use    @deprecated 3.2.0-dev (To be removed: 3.3.0)
 461      * @param bool $use_help internal variable for recursion, do not use    @deprecated 3.2.0-dev (To be removed: 3.3.0)
 462      * @param string $ext_name The extension to load language from, or empty for core files
 463      *
 464      * Examples:
 465      * <code>
 466      * $lang_set = array('posting', 'help' => 'faq');
 467      * $lang_set = array('posting', 'viewtopic', 'help' => array('bbcode', 'faq'))
 468      * $lang_set = array(array('posting', 'viewtopic'), 'help' => array('bbcode', 'faq'))
 469      * $lang_set = 'posting'
 470      * $lang_set = array('help' => 'faq', 'db' => array('help:faq', 'posting'))
 471      * </code>
 472      *
 473      * Note: $use_db and $use_help should be removed. The old function was kept for BC purposes,
 474      *         so the BC logic is handled here.
 475      *
 476      * @deprecated: 3.2.0-dev (To be removed: 3.3.0)
 477      */
 478  	function add_lang($lang_set, $use_db = false, $use_help = false, $ext_name = '')
 479      {
 480          if (is_array($lang_set))
 481          {
 482              foreach ($lang_set as $key => $lang_file)
 483              {
 484                  // Please do not delete this line.
 485                  // We have to force the type here, else [array] language inclusion will not work
 486                  $key = (string) $key;
 487  
 488                  if ($key == 'db')
 489                  {
 490                      // This is never used
 491                      $this->add_lang($lang_file, true, $use_help, $ext_name);
 492                  }
 493                  else if ($key == 'help')
 494                  {
 495                      $this->add_lang($lang_file, $use_db, true, $ext_name);
 496                  }
 497                  else if (!is_array($lang_file))
 498                  {
 499                      $this->set_lang($lang_file, $use_help, $ext_name);
 500                  }
 501                  else
 502                  {
 503                      $this->add_lang($lang_file, $use_db, $use_help, $ext_name);
 504                  }
 505              }
 506              unset($lang_set);
 507          }
 508          else if ($lang_set)
 509          {
 510              $this->set_lang($lang_set, $use_help, $ext_name);
 511          }
 512      }
 513  
 514      /**
 515       * BC function for loading language files
 516       *
 517       * @deprecated 3.2.0-dev (To be removed: 3.3.0)
 518       */
 519  	private function set_lang($lang_set, $use_help, $ext_name)
 520      {
 521          if (empty($ext_name))
 522          {
 523              $ext_name = null;
 524          }
 525  
 526          if ($use_help && strpos($lang_set, '/') !== false)
 527          {
 528              $component = dirname($lang_set) . '/help_' . basename($lang_set);
 529  
 530              if ($component[0] === '/')
 531              {
 532                  $component = substr($component, 1);
 533              }
 534          }
 535          else
 536          {
 537              $component = (($use_help) ? 'help_' : '') . $lang_set;
 538          }
 539  
 540          $this->language->add_lang($component, $ext_name);
 541      }
 542  
 543      /**
 544      * Add Language Items from an extension - use_db and use_help are assigned where needed (only use them to force inclusion)
 545      *
 546      * @param string $ext_name The extension to load language from, or empty for core files
 547      * @param mixed $lang_set specifies the language entries to include
 548      * @param bool $use_db internal variable for recursion, do not use
 549      * @param bool $use_help internal variable for recursion, do not use
 550      *
 551      * Note: $use_db and $use_help should be removed. Kept for BC purposes.
 552      *
 553      * @deprecated: 3.2.0-dev (To be removed: 3.3.0)
 554      */
 555  	function add_lang_ext($ext_name, $lang_set, $use_db = false, $use_help = false)
 556      {
 557          if ($ext_name === '/')
 558          {
 559              $ext_name = '';
 560          }
 561  
 562          $this->add_lang($lang_set, $use_db, $use_help, $ext_name);
 563      }
 564  
 565      /**
 566      * Format user date
 567      *
 568      * @param int $gmepoch unix timestamp
 569      * @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.
 570      * @param bool $forcedate force non-relative date format.
 571      *
 572      * @return mixed translated date
 573      */
 574  	function format_date($gmepoch, $format = false, $forcedate = false)
 575      {
 576          global $phpbb_dispatcher;
 577          static $utc;
 578  
 579          if (!isset($utc))
 580          {
 581              $utc = new \DateTimeZone('UTC');
 582          }
 583  
 584          $format_date_override = false;
 585          $function_arguments = func_get_args();
 586          /**
 587          * Execute code and/or override format_date()
 588          *
 589          * To override the format_date() function generated value
 590          * set $format_date_override to new return value
 591          *
 592          * @event core.user_format_date_override
 593          * @var DateTimeZone    utc Is DateTimeZone in UTC
 594          * @var array function_arguments is array comprising a function's argument list
 595          * @var string format_date_override Shall we return custom format (string) or not (false)
 596          * @since 3.2.1-RC1
 597          */
 598          $vars = array('utc', 'function_arguments', 'format_date_override');
 599          extract($phpbb_dispatcher->trigger_event('core.user_format_date_override', compact($vars)));
 600  
 601          if (!$format_date_override)
 602          {
 603              $time = new $this->datetime($this, '@' . (int) $gmepoch, $utc);
 604              $time->setTimezone($this->timezone);
 605  
 606              return $time->format($format, $forcedate);
 607          }
 608          else
 609          {
 610              return $format_date_override;
 611          }
 612      }
 613  
 614      /**
 615      * Create a \phpbb\datetime object in the context of the current user
 616      *
 617      * @since 3.1
 618      * @param string $time String in a format accepted by strtotime().
 619      * @param DateTimeZone $timezone Time zone of the time.
 620      * @return \phpbb\datetime Date time object linked to the current users locale
 621      */
 622  	public function create_datetime($time = 'now', \DateTimeZone $timezone = null)
 623      {
 624          $timezone = $timezone ?: $this->timezone;
 625          return new $this->datetime($this, $time, $timezone);
 626      }
 627  
 628      /**
 629      * Get the UNIX timestamp for a datetime in the users timezone, so we can store it in the database.
 630      *
 631      * @param    string            $format        Format of the entered date/time
 632      * @param    string            $time        Date/time with the timezone applied
 633      * @param    DateTimeZone    $timezone    Timezone of the date/time, falls back to timezone of current user
 634      * @return    int            Returns the unix timestamp
 635      */
 636  	public function get_timestamp_from_format($format, $time, \DateTimeZone $timezone = null)
 637      {
 638          $timezone = $timezone ?: $this->timezone;
 639          $date = \DateTime::createFromFormat($format, $time, $timezone);
 640          return ($date !== false) ? $date->format('U') : false;
 641      }
 642  
 643      /**
 644      * Get language id currently used by the user
 645      */
 646  	function get_iso_lang_id()
 647      {
 648          global $config, $db;
 649  
 650          if (!empty($this->lang_id))
 651          {
 652              return $this->lang_id;
 653          }
 654  
 655          if (!$this->lang_name)
 656          {
 657              $this->lang_name = $config['default_lang'];
 658          }
 659  
 660          $sql = 'SELECT lang_id
 661              FROM ' . LANG_TABLE . "
 662              WHERE lang_iso = '" . $db->sql_escape($this->lang_name) . "'";
 663          $result = $db->sql_query($sql);
 664          $this->lang_id = (int) $db->sql_fetchfield('lang_id');
 665          $db->sql_freeresult($result);
 666  
 667          return $this->lang_id;
 668      }
 669  
 670      /**
 671      * Get users profile fields
 672      */
 673  	function get_profile_fields($user_id)
 674      {
 675          global $db;
 676  
 677          if (isset($this->profile_fields))
 678          {
 679              return;
 680          }
 681  
 682          $sql = 'SELECT *
 683              FROM ' . PROFILE_FIELDS_DATA_TABLE . "
 684              WHERE user_id = $user_id";
 685          $result = $db->sql_query_limit($sql, 1);
 686          $this->profile_fields = (!($row = $db->sql_fetchrow($result))) ? array() : $row;
 687          $db->sql_freeresult($result);
 688      }
 689  
 690      /**
 691      * Specify/Get image
 692      */
 693  	function img($img, $alt = '')
 694      {
 695          $title = '';
 696  
 697          if ($alt)
 698          {
 699              $alt = $this->language->lang($alt);
 700              $title = ' title="' . $alt . '"';
 701          }
 702          return '<span class="imageset ' . $img . '"' . $title . '>' . $alt . '</span>';
 703      }
 704  
 705      /**
 706      * Get option bit field from user options.
 707      *
 708      * @param int $key option key, as defined in $keyoptions property.
 709      * @param int $data bit field value to use, or false to use $this->data['user_options']
 710      * @return bool true if the option is set in the bit field, false otherwise
 711      */
 712  	function optionget($key, $data = false)
 713      {
 714          $var = ($data !== false) ? $data : $this->data['user_options'];
 715          return phpbb_optionget($this->keyoptions[$key], $var);
 716      }
 717  
 718      /**
 719      * Set option bit field for user options.
 720      *
 721      * @param int $key Option key, as defined in $keyoptions property.
 722      * @param bool $value True to set the option, false to clear the option.
 723      * @param int $data Current bit field value, or false to use $this->data['user_options']
 724      * @return int|bool If $data is false, the bit field is modified and
 725      *                  written back to $this->data['user_options'], and
 726      *                  return value is true if the bit field changed and
 727      *                  false otherwise. If $data is not false, the new
 728      *                  bitfield value is returned.
 729      */
 730  	function optionset($key, $value, $data = false)
 731      {
 732          $var = ($data !== false) ? $data : $this->data['user_options'];
 733  
 734          $new_var = phpbb_optionset($this->keyoptions[$key], $value, $var);
 735  
 736          if ($data === false)
 737          {
 738              if ($new_var != $var)
 739              {
 740                  $this->data['user_options'] = $new_var;
 741                  return true;
 742              }
 743              else
 744              {
 745                  return false;
 746              }
 747          }
 748          else
 749          {
 750              return $new_var;
 751          }
 752      }
 753  
 754      /**
 755      * Funtion to make the user leave the NEWLY_REGISTERED system group.
 756      * @access public
 757      */
 758  	function leave_newly_registered()
 759      {
 760          if (empty($this->data['user_new']))
 761          {
 762              return false;
 763          }
 764  
 765          if (!function_exists('remove_newly_registered'))
 766          {
 767              global $phpbb_root_path, $phpEx;
 768  
 769              include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
 770          }
 771          if ($group = remove_newly_registered($this->data['user_id'], $this->data))
 772          {
 773              $this->data['group_id'] = $group;
 774  
 775          }
 776          $this->data['user_permissions'] = '';
 777          $this->data['user_new'] = 0;
 778  
 779          return true;
 780      }
 781  
 782      /**
 783      * Returns all password protected forum ids the user is currently NOT authenticated for.
 784      *
 785      * @return array     Array of forum ids
 786      * @access public
 787      */
 788  	function get_passworded_forums()
 789      {
 790          global $db;
 791  
 792          $sql = 'SELECT f.forum_id, fa.user_id
 793              FROM ' . FORUMS_TABLE . ' f
 794              LEFT JOIN ' . FORUMS_ACCESS_TABLE . " fa
 795                  ON (fa.forum_id = f.forum_id
 796                      AND fa.session_id = '" . $db->sql_escape($this->session_id) . "')
 797              WHERE f.forum_password <> ''";
 798          $result = $db->sql_query($sql);
 799  
 800          $forum_ids = array();
 801          while ($row = $db->sql_fetchrow($result))
 802          {
 803              $forum_id = (int) $row['forum_id'];
 804  
 805              if ($row['user_id'] != $this->data['user_id'])
 806              {
 807                  $forum_ids[$forum_id] = $forum_id;
 808              }
 809          }
 810          $db->sql_freeresult($result);
 811  
 812          return $forum_ids;
 813      }
 814  }


Generated: Tue Apr 7 19:42:26 2020 Cross-referenced by PHPXref 0.7.1