[ Index ]

PHP Cross Reference of phpBB-3.2.2-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          * @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          if (!$this->style)
 282          {
 283              trigger_error('NO_STYLE_DATA', E_USER_ERROR);
 284          }
 285  
 286          // Now parse the cfg file and cache it
 287          $parsed_items = $cache->obtain_cfg_items($this->style);
 288  
 289          $check_for = array(
 290              'pagination_sep'    => (string) ', '
 291          );
 292  
 293          foreach ($check_for as $key => $default_value)
 294          {
 295              $this->style[$key] = (isset($parsed_items[$key])) ? $parsed_items[$key] : $default_value;
 296              settype($this->style[$key], gettype($default_value));
 297  
 298              if (is_string($default_value))
 299              {
 300                  $this->style[$key] = htmlspecialchars($this->style[$key]);
 301              }
 302          }
 303  
 304          $template->set_style();
 305  
 306          $this->img_lang = $this->lang_name;
 307  
 308          // Call phpbb_user_session_handler() in case external application want to "bend" some variables or replace classes...
 309          // After calling it we continue script execution...
 310          phpbb_user_session_handler();
 311  
 312          /**
 313          * Execute code at the end of user setup
 314          *
 315          * @event core.user_setup_after
 316          * @since 3.1.6-RC1
 317          */
 318          $phpbb_dispatcher->dispatch('core.user_setup_after');
 319  
 320          // If this function got called from the error handler we are finished here.
 321          if (defined('IN_ERROR_HANDLER'))
 322          {
 323              return;
 324          }
 325  
 326          // Disable board if the install/ directory is still present
 327          // For the brave development army we do not care about this, else we need to comment out this everytime we develop locally
 328          if (!defined('DEBUG') && !defined('ADMIN_START') && !defined('IN_INSTALL') && !defined('IN_LOGIN') && file_exists($phpbb_root_path . 'install') && !is_file($phpbb_root_path . 'install'))
 329          {
 330              // Adjust the message slightly according to the permissions
 331              if ($auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'))
 332              {
 333                  $message = 'REMOVE_INSTALL';
 334              }
 335              else
 336              {
 337                  $message = (!empty($config['board_disable_msg'])) ? $config['board_disable_msg'] : 'BOARD_DISABLE';
 338              }
 339              trigger_error($message);
 340          }
 341  
 342          // Is board disabled and user not an admin or moderator?
 343          if ($config['board_disable'] && !defined('IN_LOGIN') && !defined('SKIP_CHECK_DISABLED') && !$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
 344          {
 345              if ($this->data['is_bot'])
 346              {
 347                  send_status_line(503, 'Service Unavailable');
 348              }
 349  
 350              $message = (!empty($config['board_disable_msg'])) ? $config['board_disable_msg'] : 'BOARD_DISABLE';
 351              trigger_error($message);
 352          }
 353  
 354          // Is load exceeded?
 355          if ($config['limit_load'] && $this->load !== false)
 356          {
 357              if ($this->load > floatval($config['limit_load']) && !defined('IN_LOGIN') && !defined('IN_ADMIN'))
 358              {
 359                  // Set board disabled to true to let the admins/mods get the proper notification
 360                  $config['board_disable'] = '1';
 361  
 362                  if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
 363                  {
 364                      if ($this->data['is_bot'])
 365                      {
 366                          send_status_line(503, 'Service Unavailable');
 367                      }
 368                      trigger_error('BOARD_UNAVAILABLE');
 369                  }
 370              }
 371          }
 372  
 373          if (isset($this->data['session_viewonline']))
 374          {
 375              // Make sure the user is able to hide his session
 376              if (!$this->data['session_viewonline'])
 377              {
 378                  // Reset online status if not allowed to hide the session...
 379                  if (!$auth->acl_get('u_hideonline'))
 380                  {
 381                      $sql = 'UPDATE ' . SESSIONS_TABLE . '
 382                          SET session_viewonline = 1
 383                          WHERE session_user_id = ' . $this->data['user_id'];
 384                      $db->sql_query($sql);
 385                      $this->data['session_viewonline'] = 1;
 386                  }
 387              }
 388              else if (!$this->data['user_allow_viewonline'])
 389              {
 390                  // the user wants to hide and is allowed to  -> cloaking device on.
 391                  if ($auth->acl_get('u_hideonline'))
 392                  {
 393                      $sql = 'UPDATE ' . SESSIONS_TABLE . '
 394                          SET session_viewonline = 0
 395                          WHERE session_user_id = ' . $this->data['user_id'];
 396                      $db->sql_query($sql);
 397                      $this->data['session_viewonline'] = 0;
 398                  }
 399              }
 400          }
 401  
 402          // Does the user need to change their password? If so, redirect to the
 403          // ucp profile reg_details page ... of course do not redirect if we're already in the ucp
 404          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))
 405          {
 406              if (strpos($this->page['query_string'], 'mode=reg_details') === false && $this->page['page_name'] != "ucp.$phpEx")
 407              {
 408                  redirect(append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=profile&amp;mode=reg_details'));
 409              }
 410          }
 411  
 412          $this->is_setup_flag = true;
 413  
 414          return;
 415      }
 416  
 417      /**
 418      * More advanced language substitution
 419      * Function to mimic sprintf() with the possibility of using phpBB's language system to substitute nullar/singular/plural forms.
 420      * Params are the language key and the parameters to be substituted.
 421      * This function/functionality is inspired by SHS` and Ashe.
 422      *
 423      * Example call: <samp>$user->lang('NUM_POSTS_IN_QUEUE', 1);</samp>
 424      *
 425      * If the first parameter is an array, the elements are used as keys and subkeys to get the language entry:
 426      * Example: <samp>$user->lang(array('datetime', 'AGO'), 1)</samp> uses $user->lang['datetime']['AGO'] as language entry.
 427      *
 428      * @deprecated 3.2.0-dev (To be removed 4.0.0)
 429      */
 430  	function lang()
 431      {
 432          $args = func_get_args();
 433          return call_user_func_array(array($this->language, 'lang'), $args);
 434      }
 435  
 436      /**
 437      * Determine which plural form we should use.
 438      * For some languages this is not as simple as for English.
 439      *
 440      * @param $number        int|float   The number we want to get the plural case for. Float numbers are floored.
 441      * @param $force_rule    mixed   False to use the plural rule of the language package
 442      *                               or an integer to force a certain plural rule
 443      * @return int|bool     The plural-case we need to use for the number plural-rule combination, false if $force_rule
 444      *                        was invalid.
 445      *
 446      * @deprecated: 3.2.0-dev (To be removed: 3.3.0)
 447      */
 448  	function get_plural_form($number, $force_rule = false)
 449      {
 450          return $this->language->get_plural_form($number, $force_rule);
 451      }
 452  
 453      /**
 454      * Add Language Items - use_db and use_help are assigned where needed (only use them to force inclusion)
 455      *
 456      * @param mixed $lang_set specifies the language entries to include
 457      * @param bool $use_db internal variable for recursion, do not use    @deprecated 3.2.0-dev (To be removed: 3.3.0)
 458      * @param bool $use_help internal variable for recursion, do not use    @deprecated 3.2.0-dev (To be removed: 3.3.0)
 459      * @param string $ext_name The extension to load language from, or empty for core files
 460      *
 461      * Examples:
 462      * <code>
 463      * $lang_set = array('posting', 'help' => 'faq');
 464      * $lang_set = array('posting', 'viewtopic', 'help' => array('bbcode', 'faq'))
 465      * $lang_set = array(array('posting', 'viewtopic'), 'help' => array('bbcode', 'faq'))
 466      * $lang_set = 'posting'
 467      * $lang_set = array('help' => 'faq', 'db' => array('help:faq', 'posting'))
 468      * </code>
 469      *
 470      * Note: $use_db and $use_help should be removed. The old function was kept for BC purposes,
 471      *         so the BC logic is handled here.
 472      *
 473      * @deprecated: 3.2.0-dev (To be removed: 3.3.0)
 474      */
 475  	function add_lang($lang_set, $use_db = false, $use_help = false, $ext_name = '')
 476      {
 477          if (is_array($lang_set))
 478          {
 479              foreach ($lang_set as $key => $lang_file)
 480              {
 481                  // Please do not delete this line.
 482                  // We have to force the type here, else [array] language inclusion will not work
 483                  $key = (string) $key;
 484  
 485                  if ($key == 'db')
 486                  {
 487                      // This is never used
 488                      $this->add_lang($lang_file, true, $use_help, $ext_name);
 489                  }
 490                  else if ($key == 'help')
 491                  {
 492                      $this->add_lang($lang_file, $use_db, true, $ext_name);
 493                  }
 494                  else if (!is_array($lang_file))
 495                  {
 496                      $this->set_lang($lang_file, $use_help, $ext_name);
 497                  }
 498                  else
 499                  {
 500                      $this->add_lang($lang_file, $use_db, $use_help, $ext_name);
 501                  }
 502              }
 503              unset($lang_set);
 504          }
 505          else if ($lang_set)
 506          {
 507              $this->set_lang($lang_set, $use_help, $ext_name);
 508          }
 509      }
 510  
 511      /**
 512       * BC function for loading language files
 513       *
 514       * @deprecated 3.2.0-dev (To be removed: 3.3.0)
 515       */
 516  	private function set_lang($lang_set, $use_help, $ext_name)
 517      {
 518          if (empty($ext_name))
 519          {
 520              $ext_name = null;
 521          }
 522  
 523          if ($use_help && strpos($lang_set, '/') !== false)
 524          {
 525              $component = dirname($lang_set) . '/help_' . basename($lang_set);
 526  
 527              if ($component[0] === '/')
 528              {
 529                  $component = substr($component, 1);
 530              }
 531          }
 532          else
 533          {
 534              $component = (($use_help) ? 'help_' : '') . $lang_set;
 535          }
 536  
 537          $this->language->add_lang($component, $ext_name);
 538      }
 539  
 540      /**
 541      * Add Language Items from an extension - use_db and use_help are assigned where needed (only use them to force inclusion)
 542      *
 543      * @param string $ext_name The extension to load language from, or empty for core files
 544      * @param mixed $lang_set specifies the language entries to include
 545      * @param bool $use_db internal variable for recursion, do not use
 546      * @param bool $use_help internal variable for recursion, do not use
 547      *
 548      * Note: $use_db and $use_help should be removed. Kept for BC purposes.
 549      *
 550      * @deprecated: 3.2.0-dev (To be removed: 3.3.0)
 551      */
 552  	function add_lang_ext($ext_name, $lang_set, $use_db = false, $use_help = false)
 553      {
 554          if ($ext_name === '/')
 555          {
 556              $ext_name = '';
 557          }
 558  
 559          $this->add_lang($lang_set, $use_db, $use_help, $ext_name);
 560      }
 561  
 562      /**
 563      * Format user date
 564      *
 565      * @param int $gmepoch unix timestamp
 566      * @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.
 567      * @param bool $forcedate force non-relative date format.
 568      *
 569      * @return mixed translated date
 570      */
 571  	function format_date($gmepoch, $format = false, $forcedate = false)
 572      {
 573          global $phpbb_dispatcher;
 574          static $utc;
 575  
 576          if (!isset($utc))
 577          {
 578              $utc = new \DateTimeZone('UTC');
 579          }
 580  
 581          $format_date_override = false;
 582          $function_arguments = func_get_args();
 583          /**
 584          * Execute code and/or override format_date()
 585          *
 586          * To override the format_date() function generated value
 587          * set $format_date_override to new return value
 588          *
 589          * @event core.user_format_date_override
 590          * @var DateTimeZone    utc Is DateTimeZone in UTC
 591          * @var array function_arguments is array comprising a function's argument list
 592          * @var string format_date_override Shall we return custom format (string) or not (false)
 593          * @since 3.2.1-RC1
 594          */
 595          $vars = array('utc', 'function_arguments', 'format_date_override');
 596          extract($phpbb_dispatcher->trigger_event('core.user_format_date_override', compact($vars)));
 597  
 598          if (!$format_date_override)
 599          {
 600              $time = new $this->datetime($this, '@' . (int) $gmepoch, $utc);
 601              $time->setTimezone($this->timezone);
 602  
 603              return $time->format($format, $forcedate);
 604          }
 605          else
 606          {
 607              return $format_date_override;
 608          }
 609      }
 610  
 611      /**
 612      * Create a \phpbb\datetime object in the context of the current user
 613      *
 614      * @since 3.1
 615      * @param string $time String in a format accepted by strtotime().
 616      * @param DateTimeZone $timezone Time zone of the time.
 617      * @return \phpbb\datetime Date time object linked to the current users locale
 618      */
 619  	public function create_datetime($time = 'now', \DateTimeZone $timezone = null)
 620      {
 621          $timezone = $timezone ?: $this->timezone;
 622          return new $this->datetime($this, $time, $timezone);
 623      }
 624  
 625      /**
 626      * Get the UNIX timestamp for a datetime in the users timezone, so we can store it in the database.
 627      *
 628      * @param    string            $format        Format of the entered date/time
 629      * @param    string            $time        Date/time with the timezone applied
 630      * @param    DateTimeZone    $timezone    Timezone of the date/time, falls back to timezone of current user
 631      * @return    int            Returns the unix timestamp
 632      */
 633  	public function get_timestamp_from_format($format, $time, \DateTimeZone $timezone = null)
 634      {
 635          $timezone = $timezone ?: $this->timezone;
 636          $date = \DateTime::createFromFormat($format, $time, $timezone);
 637          return ($date !== false) ? $date->format('U') : false;
 638      }
 639  
 640      /**
 641      * Get language id currently used by the user
 642      */
 643  	function get_iso_lang_id()
 644      {
 645          global $config, $db;
 646  
 647          if (!empty($this->lang_id))
 648          {
 649              return $this->lang_id;
 650          }
 651  
 652          if (!$this->lang_name)
 653          {
 654              $this->lang_name = $config['default_lang'];
 655          }
 656  
 657          $sql = 'SELECT lang_id
 658              FROM ' . LANG_TABLE . "
 659              WHERE lang_iso = '" . $db->sql_escape($this->lang_name) . "'";
 660          $result = $db->sql_query($sql);
 661          $this->lang_id = (int) $db->sql_fetchfield('lang_id');
 662          $db->sql_freeresult($result);
 663  
 664          return $this->lang_id;
 665      }
 666  
 667      /**
 668      * Get users profile fields
 669      */
 670  	function get_profile_fields($user_id)
 671      {
 672          global $db;
 673  
 674          if (isset($this->profile_fields))
 675          {
 676              return;
 677          }
 678  
 679          $sql = 'SELECT *
 680              FROM ' . PROFILE_FIELDS_DATA_TABLE . "
 681              WHERE user_id = $user_id";
 682          $result = $db->sql_query_limit($sql, 1);
 683          $this->profile_fields = (!($row = $db->sql_fetchrow($result))) ? array() : $row;
 684          $db->sql_freeresult($result);
 685      }
 686  
 687      /**
 688      * Specify/Get image
 689      */
 690  	function img($img, $alt = '')
 691      {
 692          $title = '';
 693  
 694          if ($alt)
 695          {
 696              $alt = $this->language->lang($alt);
 697              $title = ' title="' . $alt . '"';
 698          }
 699          return '<span class="imageset ' . $img . '"' . $title . '>' . $alt . '</span>';
 700      }
 701  
 702      /**
 703      * Get option bit field from user options.
 704      *
 705      * @param int $key option key, as defined in $keyoptions property.
 706      * @param int $data bit field value to use, or false to use $this->data['user_options']
 707      * @return bool true if the option is set in the bit field, false otherwise
 708      */
 709  	function optionget($key, $data = false)
 710      {
 711          $var = ($data !== false) ? $data : $this->data['user_options'];
 712          return phpbb_optionget($this->keyoptions[$key], $var);
 713      }
 714  
 715      /**
 716      * Set option bit field for user options.
 717      *
 718      * @param int $key Option key, as defined in $keyoptions property.
 719      * @param bool $value True to set the option, false to clear the option.
 720      * @param int $data Current bit field value, or false to use $this->data['user_options']
 721      * @return int|bool If $data is false, the bit field is modified and
 722      *                  written back to $this->data['user_options'], and
 723      *                  return value is true if the bit field changed and
 724      *                  false otherwise. If $data is not false, the new
 725      *                  bitfield value is returned.
 726      */
 727  	function optionset($key, $value, $data = false)
 728      {
 729          $var = ($data !== false) ? $data : $this->data['user_options'];
 730  
 731          $new_var = phpbb_optionset($this->keyoptions[$key], $value, $var);
 732  
 733          if ($data === false)
 734          {
 735              if ($new_var != $var)
 736              {
 737                  $this->data['user_options'] = $new_var;
 738                  return true;
 739              }
 740              else
 741              {
 742                  return false;
 743              }
 744          }
 745          else
 746          {
 747              return $new_var;
 748          }
 749      }
 750  
 751      /**
 752      * Funtion to make the user leave the NEWLY_REGISTERED system group.
 753      * @access public
 754      */
 755  	function leave_newly_registered()
 756      {
 757          if (empty($this->data['user_new']))
 758          {
 759              return false;
 760          }
 761  
 762          if (!function_exists('remove_newly_registered'))
 763          {
 764              global $phpbb_root_path, $phpEx;
 765  
 766              include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
 767          }
 768          if ($group = remove_newly_registered($this->data['user_id'], $this->data))
 769          {
 770              $this->data['group_id'] = $group;
 771  
 772          }
 773          $this->data['user_permissions'] = '';
 774          $this->data['user_new'] = 0;
 775  
 776          return true;
 777      }
 778  
 779      /**
 780      * Returns all password protected forum ids the user is currently NOT authenticated for.
 781      *
 782      * @return array     Array of forum ids
 783      * @access public
 784      */
 785  	function get_passworded_forums()
 786      {
 787          global $db;
 788  
 789          $sql = 'SELECT f.forum_id, fa.user_id
 790              FROM ' . FORUMS_TABLE . ' f
 791              LEFT JOIN ' . FORUMS_ACCESS_TABLE . " fa
 792                  ON (fa.forum_id = f.forum_id
 793                      AND fa.session_id = '" . $db->sql_escape($this->session_id) . "')
 794              WHERE f.forum_password <> ''";
 795          $result = $db->sql_query($sql);
 796  
 797          $forum_ids = array();
 798          while ($row = $db->sql_fetchrow($result))
 799          {
 800              $forum_id = (int) $row['forum_id'];
 801  
 802              if ($row['user_id'] != $this->data['user_id'])
 803              {
 804                  $forum_ids[$forum_id] = $forum_id;
 805              }
 806          }
 807          $db->sql_freeresult($result);
 808  
 809          return $forum_ids;
 810      }
 811  }


Generated: Thu Jan 11 23:14:31 2018 Cross-referenced by PHPXref 0.7.1